Class BlockDiskCache<K,V>
java.lang.Object
org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCache<K,V>
org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheEventLogging<K,V>
org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCache<K,V>
org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCache<K,V>
- All Implemented Interfaces:
AuxiliaryCache<K,
,V> ICache<K,
,V> ICacheType
,IRequireScheduler
There is one BlockDiskCache per region. It manages the key and data store.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCache
AbstractDiskCache.MyCacheListener
Nested classes/interfaces inherited from interface org.apache.commons.jcs3.engine.behavior.ICacheType
ICacheType.CacheType
-
Field Summary
Fields inherited from interface org.apache.commons.jcs3.engine.behavior.ICache
NAME_COMPONENT_DELIMITER
-
Constructor Summary
ConstructorsConstructorDescriptionBlockDiskCache
(BlockDiskCacheAttributes cacheAttributes) Constructs the BlockDisk after setting up the root directory.BlockDiskCache
(BlockDiskCacheAttributes cacheAttributes, IElementSerializer elementSerializer) Constructs the BlockDisk after setting up the root directory. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Internal method that handles the disposal.protected void
freeBlocks
(int[] blocksToFree) Add these blocks to the emptyBlock list.Returns the attributes.protected String
This is used by the event logging.Return the keys in this cache.int
getSize()
Returns the number of keys.Returns info about the disk cache.void
Dispose of the disk cache in a background thread.protected ICacheElement<K,
V> processGet
(K key) Gets the ICacheElement<K, V> for the key if it is in the cache.Map<K,
ICacheElement<K, V>> processGetMatching
(String pattern) Gets matching items from the cache.protected boolean
processRemove
(K key) Returns true if the removal was successful; or false if there is nothing to remove.protected void
Resets the keyfile, the disk file, and the memory key map.protected void
processUpdate
(ICacheElement<K, V> element) Writes an element to disk.void
setScheduledExecutorService
(ScheduledExecutorService scheduledExecutor) Inject an instance of a central ScheduledExecutorServiceprotected boolean
We need to verify that the file on disk uses the same block size and that the file is the proper size.Methods inherited from class org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCache
dispose, doDispose, doGet, doGetMatching, doRemove, doRemoveAll, doUpdate, get, getCacheName, getCacheType, getEventLoggingExtraInfo, getMatching, getStats, getStatus, isAlive, remove, removeAll, setAlive, update
Methods inherited from class org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheEventLogging
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLogging
Methods inherited from class org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCache
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, processGetMultiple, setCacheEventLogger, setElementSerializer, setKeyMatcher
-
Constructor Details
-
BlockDiskCache
Constructs the BlockDisk after setting up the root directory.- Parameters:
cacheAttributes
-
-
BlockDiskCache
public BlockDiskCache(BlockDiskCacheAttributes cacheAttributes, IElementSerializer elementSerializer) Constructs the BlockDisk after setting up the root directory.- Parameters:
cacheAttributes
-elementSerializer
- used if supplied, the super's super will not set a null
-
-
Method Details
-
setScheduledExecutorService
Description copied from interface:IRequireScheduler
Inject an instance of a central ScheduledExecutorService- Specified by:
setScheduledExecutorService
in interfaceIRequireScheduler
- See Also:
-
verifyDisk
We need to verify that the file on disk uses the same block size and that the file is the proper size.- Returns:
- true if it looks ok
-
getKeySet
Return the keys in this cache.- Specified by:
getKeySet
in interfaceAuxiliaryCache<K,
V> - Specified by:
getKeySet
in classAbstractDiskCache<K,
V> - Returns:
- a set of the key type TODO This should probably be done in chunks with a range passed in. This will be a problem if someone puts a 1,000,000 or so items in a region.
- Throws:
IOException
- if access to the auxiliary cache fails- See Also:
-
processGetMatching
Gets matching items from the cache.- Specified by:
processGetMatching
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
pattern
-- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache matching keys
-
getSize
Returns the number of keys.(non-Javadoc)
-
processGet
Gets the ICacheElement<K, V> for the key if it is in the cache. The program flow is as follows:- Make sure the disk cache is alive.
- Get a read lock.
- See if the key is in the key store.
- If we found a key, ask the BlockDisk for the object at the blocks..
- Release the lock.
- Specified by:
processGet
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
key
-- Returns:
- ICacheElement
- See Also:
-
processUpdate
Writes an element to disk. The program flow is as follows:- Acquire write lock.
- See id an item exists for this key.
- If an item already exists, add its blocks to the remove list.
- Have the Block disk write the item.
- Create a descriptor and add it to the key map.
- Release the write lock.
- Specified by:
processUpdate
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
element
-- See Also:
-
processRemove
Returns true if the removal was successful; or false if there is nothing to remove. Current implementation always result in a disk orphan.- Specified by:
processRemove
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
key
-- Returns:
- true if removed anything
- See Also:
-
processRemoveAll
Resets the keyfile, the disk file, and the memory key map.- Specified by:
processRemoveAll
in classAbstractAuxiliaryCacheEventLogging<K,
V> - See Also:
-
processDispose
Dispose of the disk cache in a background thread. Joins against this thread to put a cap on the disposal time.TODO make dispose window configurable.
- Specified by:
processDispose
in classAbstractAuxiliaryCacheEventLogging<K,
V>
-
disposeInternal
Internal method that handles the disposal. -
getAuxiliaryCacheAttributes
Returns the attributes.- Specified by:
getAuxiliaryCacheAttributes
in interfaceAuxiliaryCache<K,
V> - Returns:
- the attributes for the auxiliary cache
- See Also:
-
freeBlocks
Add these blocks to the emptyBlock list.- Parameters:
blocksToFree
-
-
getStatistics
Returns info about the disk cache.- Specified by:
getStatistics
in interfaceAuxiliaryCache<K,
V> - Overrides:
getStatistics
in classAbstractDiskCache<K,
V> - Returns:
- the historical and statistical data for a region's auxiliary cache.
- See Also:
-
getDiskLocation
This is used by the event logging.- Specified by:
getDiskLocation
in classAbstractDiskCache<K,
V> - Returns:
- the location of the disk, either path or ip.
-