org.apache.jcs.auxiliary.disk.file
Class FileDiskCache

java.lang.Object
  extended by org.apache.jcs.auxiliary.AbstractAuxiliaryCache
      extended by org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging
          extended by org.apache.jcs.auxiliary.disk.AbstractDiskCache
              extended by org.apache.jcs.auxiliary.disk.file.FileDiskCache
All Implemented Interfaces:
Serializable, AuxiliaryCache, ICache, ICacheType

public class FileDiskCache
extends AbstractDiskCache

This disk cache writes each item to a separate file. This is for regions with very few items, perhaps big ones.

This is a fairly simple implementation. All the disk writing is handled right here. It's not clear that anything more complicated is needed.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache
alive, cacheEventQueue, cacheName, purgatory, purgHits
 
Fields inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
cacheEventLogger, elementSerializer, keyMatcher
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheType
CACHE_HUB, DISK_CACHE, LATERAL_CACHE, REMOTE_CACHE
 
Constructor Summary
FileDiskCache(FileDiskCacheAttributes cacheAttributes)
          Constructor for the DiskCache object.
FileDiskCache(FileDiskCacheAttributes cattr, IElementSerializer elementSerializer)
          Constructor for the DiskCache object.
 
Method Summary
protected  File file(Serializable key)
          Creates the file for a key.
 AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
          This returns the generic attributes for an auxiliary cache.
protected  File getDirectory()
           
protected  String getDiskLocation()
          This is used by the event logging.
 Set getGroupKeys(String groupName)
          The keys in a group.
 int getSize()
          Size cannot be determined without knowledge of the cache implementation, so subclasses will need to implement this method.
protected  void processDispose()
          Sets alive to false.
protected  ICacheElement processGet(Serializable key)
          Looks for a file matching the key.
protected  Map processGetMatching(String pattern)
          Implementation of getMatching.
protected  boolean processRemove(Serializable key)
          Removes the file.
protected  void processRemoveAll()
          Remove all the files in the directory.
protected  void processUpdate(ICacheElement element)
          We create a temp file with the new contents, remove the old if it exists, and then rename the temp.
protected  void setDirectory(File directory)
           
 
Methods inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache
dispose, doDispose, doGet, doGetMatching, doRemove, doRemoveAll, doUpdate, get, getCacheName, getCacheType, getEventLoggingExtraInfo, getMatching, getStatistics, getStats, 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
 

Constructor Detail

FileDiskCache

public FileDiskCache(FileDiskCacheAttributes cacheAttributes)
Constructor for the DiskCache object.

Parameters:
cacheAttributes -

FileDiskCache

public FileDiskCache(FileDiskCacheAttributes cattr,
                     IElementSerializer elementSerializer)
Constructor for the DiskCache object. Will be marked alive if the directory cannot be created.

Parameters:
cattr -
elementSerializer - used if supplied, the super's super will not set a null
Method Detail

file

protected File file(Serializable key)
Creates the file for a key. Filenames and keys can be passed into this method. It must be idempotent.

Protected for testing.

Parameters:
key -
Returns:
the file for the key

getGroupKeys

public Set getGroupKeys(String groupName)
Description copied from class: AbstractDiskCache
The keys in a group.

(non-Javadoc)

Specified by:
getGroupKeys in interface AuxiliaryCache
Specified by:
getGroupKeys in class AbstractDiskCache
Parameters:
groupName -
Returns:
Set
See Also:
AuxiliaryCache.getGroupKeys(java.lang.String)

getSize

public int getSize()
Description copied from class: AbstractDiskCache
Size cannot be determined without knowledge of the cache implementation, so subclasses will need to implement this method.

Specified by:
getSize in interface ICache
Specified by:
getSize in class AbstractDiskCache
Returns:
dir.list().length
See Also:
ICache.getSize()

getAuxiliaryCacheAttributes

public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
Description copied from interface: AuxiliaryCache
This returns the generic attributes for an auxiliary cache. Most implementations will cast this to a more specific type.

Returns:
AuxiliaryCacheAttributes

getDiskLocation

protected String getDiskLocation()
Description copied from class: AbstractDiskCache
This is used by the event logging.

Specified by:
getDiskLocation in class AbstractDiskCache
Returns:
String the path to the directory

processDispose

protected void processDispose()
                       throws IOException
Sets alive to false.

Specified by:
processDispose in class AbstractAuxiliaryCacheEventLogging
Throws:
IOException

processGet

protected ICacheElement processGet(Serializable key)
                            throws IOException
Looks for a file matching the key. If it exists, reads the file.

Specified by:
processGet in class AbstractAuxiliaryCacheEventLogging
Parameters:
key -
Returns:
ICacheElement
Throws:
IOException

processGetMatching

protected Map processGetMatching(String pattern)
                          throws IOException
Description copied from class: AbstractAuxiliaryCacheEventLogging
Implementation of getMatching.

Specified by:
processGetMatching in class AbstractAuxiliaryCacheEventLogging
Parameters:
pattern -
Returns:
Map
Throws:
IOException

processRemove

protected boolean processRemove(Serializable key)
                         throws IOException
Removes the file.

Specified by:
processRemove in class AbstractAuxiliaryCacheEventLogging
Parameters:
key -
Returns:
true if the item was removed
Throws:
IOException

processRemoveAll

protected void processRemoveAll()
                         throws IOException
Remove all the files in the directory.

Assumes that this is the only region in the directory. We could add a region prefix to the files and only delete those, but the region should create a directory.

Specified by:
processRemoveAll in class AbstractAuxiliaryCacheEventLogging
Throws:
IOException

processUpdate

protected void processUpdate(ICacheElement element)
                      throws IOException
We create a temp file with the new contents, remove the old if it exists, and then rename the temp.

Specified by:
processUpdate in class AbstractAuxiliaryCacheEventLogging
Parameters:
element -
Throws:
IOException

setDirectory

protected void setDirectory(File directory)
Parameters:
directory - the directory to set

getDirectory

protected File getDirectory()
Returns:
the directory


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