|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jcs.auxiliary.AbstractAuxiliaryCache<K,V>
org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging<K,V>
org.apache.jcs.auxiliary.disk.AbstractDiskCache<K,V>
org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache<K,V>
public class IndexedDiskCache<K extends Serializable,V extends Serializable>
Disk cache that uses a RandomAccessFile with keys stored in memory. The maximum number of keys stored in memory is configurable. The disk cache tries to recycle spots on disk to limit file expansion.
| Nested Class Summary | |
|---|---|
class |
IndexedDiskCache.LRUMap
Class for recycling and lru. |
protected static class |
IndexedDiskCache.PositionComparator
Compares IndexedDiskElementDescriptor based on their position. |
| Nested classes/interfaces inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache |
|---|
AbstractDiskCache.MyCacheListener |
| Nested classes/interfaces inherited from interface org.apache.jcs.engine.behavior.ICacheType |
|---|
ICacheType.CacheType |
| Field Summary | |
|---|---|
protected Thread |
currentOptimizationThread
The thread optimizing the file. |
protected static org.apache.commons.logging.Log |
log
The logger |
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. |
| Fields inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache |
|---|
alive, cacheEventQueue, cacheName, purgatory, purgHits, removeAllLock |
| Fields inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache |
|---|
cacheEventLogger, elementSerializer, keyMatcher |
| Constructor Summary | |
|---|---|
IndexedDiskCache(IndexedDiskCacheAttributes cacheAttributes)
Constructor for the DiskCache object. |
|
IndexedDiskCache(IndexedDiskCacheAttributes cattr,
IElementSerializer elementSerializer)
Constructor for the DiskCache object. |
|
| Method Summary | |
|---|---|
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> |
getGroupKeys(String groupName)
Gets the group keys from the disk. |
Set<String> |
getGroupNames()
Gets the group names from the disk. |
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. |
| Methods inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache |
|---|
dispose, doDispose, doGet, doGetMatching, doRemove, doRemoveAll, doUpdate, get, getCacheName, getCacheType, getEventLoggingExtraInfo, getMatching, getStatus, processGetMultiple, remove, removeAll, update |
| Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging |
|---|
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLogging |
| Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache |
|---|
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, setCacheEventLogger, setElementSerializer, setKeyMatcher |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.apache.jcs.auxiliary.AuxiliaryCache |
|---|
setCacheEventLogger, setElementSerializer |
| Methods inherited from interface org.apache.jcs.engine.behavior.ICache |
|---|
getMultiple, setKeyMatcher |
| Field Detail |
|---|
protected static final org.apache.commons.logging.Log log
protected final String logCacheName
protected volatile Thread currentOptimizationThread
protected ReentrantReadWriteLock storageLock
| Constructor Detail |
|---|
public IndexedDiskCache(IndexedDiskCacheAttributes cacheAttributes)
cacheAttributes -
public IndexedDiskCache(IndexedDiskCacheAttributes cattr,
IElementSerializer elementSerializer)
cattr - elementSerializer - used if supplied, the super's super will not set a null| Method Detail |
|---|
protected void loadKeys()
throws InterruptedException
InterruptedExceptionprotected 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 extends Serializable,V extends Serializable>ce - The ICacheElementprotected ICacheElement<K,V> processGet(K key)
processGet in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>key -
AbstractDiskCache.doGet(K)public Map<K,ICacheElement<K,V>> processGetMatching(String pattern)
processGetMatching in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>pattern -
public Set<K> getGroupKeys(String groupName)
getGroupKeys in interface AuxiliaryCache<K extends Serializable,V extends Serializable>getGroupKeys in class AbstractDiskCache<K extends Serializable,V extends Serializable>AuxiliaryCache.getGroupKeys(java.lang.String)public Set<String> getGroupNames()
getGroupNames in interface AuxiliaryCache<K extends Serializable,V extends Serializable>getGroupNames in class AbstractDiskCache<K extends Serializable,V extends Serializable>AuxiliaryCache.getGroupKeys(java.lang.String)protected boolean processRemove(K key)
processRemove in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>key -
public void processRemoveAll()
processRemoveAll in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>public void processDispose()
TODO make dispose window configurable.
processDispose in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>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 extends Serializable,V extends Serializable>getSize in class AbstractDiskCache<K extends Serializable,V extends Serializable>ICache.getSize()protected int getRecyleBinSize()
protected int getRecyleCount()
protected long getBytesFree()
protected long getDataFileSize()
throws IOException
IOExceptionpublic void dump()
public void dump(boolean dumpValues)
dumpValues - A boolean indicating if values should be dumped.public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
AuxiliaryCache
public String getStats()
getStats in interface ICache<K extends Serializable,V extends Serializable>getStats in class AbstractDiskCache<K extends Serializable,V extends Serializable>public IStats getStatistics()
(non-Javadoc)
getStatistics in interface AuxiliaryCache<K extends Serializable,V extends Serializable>getStatistics in class AbstractDiskCache<K extends Serializable,V extends Serializable>AuxiliaryCache.getStatistics()protected int getTimesOptimized()
protected String getDiskLocation()
getDiskLocation in class AbstractDiskCache<K extends Serializable,V extends Serializable>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||