public class IndexedDiskCache<K,V> extends AbstractDiskCache<K,V>
Modifier and Type | Class and Description |
---|---|
class |
IndexedDiskCache.LRUMap
Class for recycling and lru.
|
protected static class |
IndexedDiskCache.PositionComparator
Compares IndexedDiskElementDescriptor based on their position.
|
AbstractDiskCache.MyCacheListener
ICacheType.CacheType
Modifier and Type | Field and Description |
---|---|
protected String |
logCacheName
Cache name used in log messages
|
protected ReentrantReadWriteLock |
storageLock
Use this lock to synchronize reads and writes to the underlying storage mechanism.
|
alive, cacheEventQueue, cacheName, purgatory, purgHits, removeAllLock
Constructor and Description |
---|
IndexedDiskCache(IndexedDiskCacheAttributes cacheAttributes)
Constructor for the DiskCache object.
|
IndexedDiskCache(IndexedDiskCacheAttributes cattr,
IElementSerializer elementSerializer)
Constructor for the DiskCache object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addToRecycleBin(IndexedDiskElementDescriptor ded)
Add descriptor to recycle bin if it is not null.
|
protected boolean |
checkForDedOverlaps(IndexedDiskElementDescriptor[] sortedDescriptors)
Detects any overlapping elements.
|
protected void |
disposeInternal()
Internal method that handles the disposal.
|
protected void |
doOptimizeRealTime()
Performs the check for optimization, and if it is required, do it.
|
void |
dump()
For debugging.
|
void |
dump(boolean dumpValues)
For debugging.
|
AuxiliaryCacheAttributes |
getAuxiliaryCacheAttributes()
This returns the generic attributes for an auxiliary cache.
|
protected long |
getBytesFree()
Returns the number of bytes that are free.
|
protected long |
getDataFileSize()
This is for debugging and testing.
|
protected String |
getDiskLocation()
This is used by the event logging.
|
Set<K> |
getKeySet()
Return the keys in this cache.
|
protected int |
getRecyleBinSize()
Returns the size of the recyclebin in number of elements.
|
protected int |
getRecyleCount()
Returns the number of times we have used spots from the recycle bin.
|
int |
getSize()
Returns the current cache size.
|
IStats |
getStatistics()
Returns info about the disk cache.
|
String |
getStats()
Gets basic stats for the disk cache.
|
protected int |
getTimesOptimized()
This is exposed for testing.
|
protected void |
loadKeys()
Loads the keys from the .key file.
|
protected void |
optimizeFile()
File optimization is handled by this method.
|
void |
processDispose()
Dispose of the disk cache in a background thread.
|
protected ICacheElement<K,V> |
processGet(K key)
Gets the key, then goes to disk to get the object.
|
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.
|
void |
processRemoveAll()
Remove all the items from the disk cache by reseting everything.
|
protected void |
processUpdate(ICacheElement<K,V> ce)
Update the disk cache.
|
protected void |
saveKeys()
Saves key file to disk.
|
dispose, doDispose, doGet, doGetMatching, doRemove, doRemoveAll, doUpdate, get, getCacheName, getCacheType, getEventLoggingExtraInfo, getMatching, getStatus, processGetMultiple, remove, removeAll, update
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLogging
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, setCacheEventLogger, setElementSerializer, setKeyMatcher
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setCacheEventLogger, setElementSerializer
getMultiple, setKeyMatcher
protected final String logCacheName
protected ReentrantReadWriteLock storageLock
public IndexedDiskCache(IndexedDiskCacheAttributes cacheAttributes)
cacheAttributes
- public IndexedDiskCache(IndexedDiskCacheAttributes cattr, IElementSerializer elementSerializer)
cattr
- elementSerializer
- used if supplied, the super's super will not set a nullprotected void loadKeys() throws InterruptedException
InterruptedException
protected boolean checkForDedOverlaps(IndexedDiskElementDescriptor[] sortedDescriptors)
The total length of an item is IndexedDisk.RECORD_HEADER + ded.len.
sortedDescriptors
- protected void saveKeys()
protected void processUpdate(ICacheElement<K,V> ce)
processUpdate
in class AbstractAuxiliaryCacheEventLogging<K,V>
ce
- The ICacheElementprotected ICacheElement<K,V> processGet(K key)
processGet
in class AbstractAuxiliaryCacheEventLogging<K,V>
key
- AbstractDiskCache.doGet(K)
public Map<K,ICacheElement<K,V>> processGetMatching(String pattern)
processGetMatching
in class AbstractAuxiliaryCacheEventLogging<K,V>
pattern
- public Set<K> getKeySet() throws IOException
getKeySet
in interface AuxiliaryCache<K,V>
getKeySet
in class AbstractDiskCache<K,V>
IOException
- if access to the auxiliary cache failsAbstractDiskCache.getKeySet()
protected boolean processRemove(K key)
processRemove
in class AbstractAuxiliaryCacheEventLogging<K,V>
key
- public void processRemoveAll()
processRemoveAll
in class AbstractAuxiliaryCacheEventLogging<K,V>
public void processDispose()
TODO make dispose window configurable.
processDispose
in class AbstractAuxiliaryCacheEventLogging<K,V>
protected void disposeInternal()
protected void addToRecycleBin(IndexedDiskElementDescriptor ded)
This is called in three places: (1) When an item is removed. All item removals funnel down to the removeSingleItem method. (2) When an item on disk is updated with a value that will not fit in the previous slot. (3) When the max key size is reached, the freed slot will be added.
The recylebin is not a set. If a slot it added twice, it will result in the wrong data being returned.
ded
- protected void doOptimizeRealTime()
protected void optimizeFile()
public int getSize()
getSize
in interface ICache<K,V>
getSize
in class AbstractDiskCache<K,V>
ICache.getSize()
protected int getRecyleBinSize()
protected int getRecyleCount()
protected long getBytesFree()
protected long getDataFileSize() throws IOException
IOException
public void dump()
public void dump(boolean dumpValues)
dumpValues
- A boolean indicating if values should be dumped.public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
AuxiliaryCache
public String getStats()
public IStats getStatistics()
(non-Javadoc)
getStatistics
in interface AuxiliaryCache<K,V>
getStatistics
in class AbstractDiskCache<K,V>
AuxiliaryCache.getStatistics()
protected int getTimesOptimized()
protected String getDiskLocation()
getDiskLocation
in class AbstractDiskCache<K,V>
Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.