org.apache.jcs.auxiliary.disk.indexed
Class IndexedDiskCache

java.lang.Object
  extended byorg.apache.jcs.auxiliary.disk.AbstractDiskCache
      extended byorg.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache
All Implemented Interfaces:
AuxiliaryCache, ICache, ICacheType, java.io.Serializable

public class IndexedDiskCache
extends AbstractDiskCache

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.

Version:
$Id: IndexedDiskCache.java 378115 2006-02-15 23:07:30Z asmuts $
See Also:
Serialized Form

Nested Class Summary
 class IndexedDiskCache.LRUMap
          class for recylcing and lru
 
Field Summary
protected  EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock storageLock
          use this lock to synchronize reads and writes to the underlying storage mechansism.
 
Fields inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache
alive, cacheEventQueue, cacheName, purgatory, purgHits
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheType
CACHE_HUB, DISK_CACHE, LATERAL_CACHE, REMOTE_CACHE
 
Constructor Summary
IndexedDiskCache(IndexedDiskCacheAttributes cattr)
          Constructor for the DiskCache object
 
Method Summary
 void doDispose()
          Dispose of the disk cache in a background thread.
protected  ICacheElement doGet(java.io.Serializable key)
          Get a value from the persistent store.
 void doOptimizeRealTime()
          Dispose of the disk cache in a background thread.
 boolean doRemove(java.io.Serializable key)
          Returns true if the removal was succesful; or false if there is nothing to remove.
 void doRemoveAll()
          Remove all the items fromt he disk cache by reseting everything.
 void doUpdate(ICacheElement ce)
          Update the disk cache.
 void dump()
          For debugging.
protected  long getDataFileSize()
          This is for debugging and testing.
 java.util.Set getGroupKeys(java.lang.String groupName)
          Gets the set of keys of objects currently in the group
 int getSize()
          Returns the current cache size.
 IStats getStatistics()
          Returns the historical and statistical data for a region's auxiliary cache.
 java.lang.String getStats()
          Gets basic stats for the disk cache.
protected  void loadKeys()
          Loads the keys from the .key file.
protected  void optimizeFile()
          Note: synchronization currently must be managed by the caller method-- dispose.
protected  void optimizeRealTime()
          Realtime optimization is handled by this method.
protected  void saveKeys()
          Saves key file to disk.
 
Methods inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache
dispose, get, getCacheName, getCacheType, getStatus, remove, removeAll, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storageLock

protected EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock storageLock
use this lock to synchronize reads and writes to the underlying storage mechansism.

Constructor Detail

IndexedDiskCache

public IndexedDiskCache(IndexedDiskCacheAttributes cattr)
Constructor for the DiskCache object

Parameters:
cattr -
Method Detail

loadKeys

protected void loadKeys()
                 throws java.lang.InterruptedException
Loads the keys from the .key file. The keys are stored in a HashMap on disk. This is converted into a LRUMap.

Throws:
java.lang.InterruptedException

saveKeys

protected void saveKeys()
Saves key file to disk. This converts the LRUMap to a HashMap for deserialzation.


doUpdate

public void doUpdate(ICacheElement ce)
Update the disk cache. Called from the Queue. Makes sure the Item has not been retireved from purgatory while in queue for disk. Remove items from purgatory when they go to disk.

Specified by:
doUpdate in class AbstractDiskCache
Parameters:
ce -

doGet

protected ICacheElement doGet(java.io.Serializable key)
Description copied from class: AbstractDiskCache
Get a value from the persistent store.

Specified by:
doGet in class AbstractDiskCache
Parameters:
key -
Returns:
ICacheElement or null
See Also:
AbstractDiskCache.doGet(java.io.Serializable)

getGroupKeys

public java.util.Set getGroupKeys(java.lang.String groupName)
Description copied from interface: AuxiliaryCache
Gets the set of keys of objects currently in the group

Specified by:
getGroupKeys in interface AuxiliaryCache
Specified by:
getGroupKeys in class AbstractDiskCache

doRemove

public boolean doRemove(java.io.Serializable key)
Returns true if the removal was succesful; or false if there is nothing to remove. Current implementation always result in a disk orphan.

Specified by:
doRemove in class AbstractDiskCache
Parameters:
key -
Returns:

doRemoveAll

public void doRemoveAll()
Remove all the items fromt he disk cache by reseting everything.

Specified by:
doRemoveAll in class AbstractDiskCache

doDispose

public void doDispose()
Dispose of the disk cache in a background thread. Joins against this thread to put a cap on the disposal time.

Specified by:
doDispose in class AbstractDiskCache

doOptimizeRealTime

public void doOptimizeRealTime()
Dispose of the disk cache in a background thread. Joins against this thread to put a cap on the disposal time.


optimizeRealTime

protected void optimizeRealTime()
Realtime optimization is handled by this method. It works in this way:


optimizeFile

protected void optimizeFile()
Note: synchronization currently must be managed by the caller method-- dispose.


getSize

public int getSize()
Returns the current cache size.

Specified by:
getSize in interface AuxiliaryCache
Specified by:
getSize in class AbstractDiskCache
Returns:
The size value
See Also:
ICache.getSize()

getDataFileSize

protected long getDataFileSize()
                        throws java.io.IOException
This is for debugging and testing.

Returns:
the length of the data file.
Throws:
java.io.IOException

dump

public void dump()
For debugging.


getStats

public java.lang.String getStats()
Gets basic stats for the disk cache.

Specified by:
getStats in interface ICache
Overrides:
getStats in class AbstractDiskCache
Returns:
String

getStatistics

public IStats getStatistics()
Description copied from interface: AuxiliaryCache
Returns the historical and statistical data for a region's auxiliary cache.

Specified by:
getStatistics in interface AuxiliaryCache
Overrides:
getStatistics in class AbstractDiskCache


Copyright © 2002-2007 Apache Software Foundation. All Rights Reserved.