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

Version:
$Id: IndexedDiskCache.java,v 1.7 2003/08/22 11:57:17 mpoeschl Exp $
Author:
Aaron Smuts, James Taylor
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache
 
Field Summary
(package private)  IndexedDiskCacheAttributes cattr
           
private  IndexedDisk dataFile
           
private  java.lang.String fileName
           
private  IndexedDisk keyFile
           
private  java.util.HashMap keyHash
           
private static org.apache.commons.logging.Log log
           
private  java.io.File rafDir
           
protected  ReadWriteLock storageLock
          Each instance of a Disk cache should 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, lock, locker, 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()
          Description of the Method
protected  ICacheElement doGet(java.io.Serializable key)
          Get a value from the persistent store.
 boolean doRemove(java.io.Serializable key)
          Returns true if the removal was succesful; or false if there is nothing to remove.
 void doRemoveAll()
          Description of the Method
 void doUpdate(ICacheElement ce)
          Update the disk cache.
 void dump()
          For debugging.
 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.
private  void loadKeys()
          Description of the Method
private  void optimizeFile()
          Note: synchronization currently managed by the only caller method - dispose.
private  CacheElement readElement(java.io.Serializable key)
           
private  void reset()
          handle error by last resort, force content update, or removeall
private  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

log

private static final org.apache.commons.logging.Log log

fileName

private java.lang.String fileName

dataFile

private IndexedDisk dataFile

keyFile

private IndexedDisk keyFile

keyHash

private java.util.HashMap keyHash

rafDir

private java.io.File rafDir

cattr

IndexedDiskCacheAttributes cattr

storageLock

protected ReadWriteLock storageLock
Each instance of a Disk cache should 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

private void loadKeys()
               throws java.lang.InterruptedException
Description of the Method

Throws:
java.lang.InterruptedException

saveKeys

private void saveKeys()
Saves key file to disk


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

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 - Key to locate value for.
Returns:
An object matching key, or null.
See Also:
AbstractDiskCache.doGet(java.io.Serializable)

readElement

private CacheElement readElement(java.io.Serializable key)
                          throws java.lang.Exception
Throws:
java.lang.Exception

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()
Description of the Method

Specified by:
doRemoveAll in class AbstractDiskCache

reset

private void reset()
handle error by last resort, force content update, or removeall


doDispose

public void doDispose()
Description of the Method

Specified by:
doDispose in class AbstractDiskCache

optimizeFile

private void optimizeFile()
Note: synchronization currently managed by the only 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

dump

public void dump()
For debugging.