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.MyCacheListenerNested 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 voidInternal method that handles the disposal.protected voidfreeBlocks(int[] blocksToFree) Add these blocks to the emptyBlock list.Returns the attributes.protected StringThis is used by the event logging.Return the keys in this cache.intgetSize()Returns the number of keys.Returns info about the disk cache.voidDispose 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 booleanprocessRemove(K key) Returns true if the removal was successful; or false if there is nothing to remove.protected voidResets the keyfile, the disk file, and the memory key map.protected voidprocessUpdate(ICacheElement<K, V> element) Writes an element to disk.voidsetScheduledExecutorService(ScheduledExecutorService scheduledExecutor) Inject an instance of a central ScheduledExecutorServiceprotected booleanWe 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, updateMethods inherited from class org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheEventLogging
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLoggingMethods 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:IRequireSchedulerInject an instance of a central ScheduledExecutorService- Specified by:
setScheduledExecutorServicein 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:
getKeySetin interfaceAuxiliaryCache<K,V> - Specified by:
getKeySetin 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:
processGetMatchingin 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:
processGetin 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:
processUpdatein 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:
processRemovein 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:
processRemoveAllin 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:
processDisposein classAbstractAuxiliaryCacheEventLogging<K,V>
-
disposeInternal
Internal method that handles the disposal. -
getAuxiliaryCacheAttributes
Returns the attributes.- Specified by:
getAuxiliaryCacheAttributesin 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:
getStatisticsin interfaceAuxiliaryCache<K,V> - Overrides:
getStatisticsin 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:
getDiskLocationin classAbstractDiskCache<K,V> - Returns:
- the location of the disk, either path or ip.
-