com.opensymphony.oscache.plugins.diskpersistence
Class HashDiskPersistenceListener

java.lang.Object
  extended by com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener
      extended by com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener
All Implemented Interfaces:
PersistenceListener, Serializable

public class HashDiskPersistenceListener
extends AbstractDiskPersistenceListener

Persists cache data to disk. Provides a hash of the standard key name as the file name. A configurable hash algorithm is used to create a digest of the cache key for the disk filename. This is to allow for more sane filenames for objects which dont generate friendly cache keys.

Author:
Jason Parrott
See Also:
Serialized Form

Field Summary
static String DEFAULT_HASH_ALGORITHM
           
private static int DIR_LEVELS
           
static String HASH_ALGORITHM_KEY
           
protected  MessageDigest md
           
(package private) static String[] PSEUDO
           
 
Fields inherited from class com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener
APPLICATION_CACHE_SUBPATH, CACHE_EXTENSION, CACHE_PATH_KEY, CONTEXT_TMPDIR, GROUP_DIRECTORY, SESSION_CACHE_SUBPATH
 
Constructor Summary
HashDiskPersistenceListener()
           
 
Method Summary
(package private) static String byteArrayToHexString(byte[] in)
          Nibble conversion.
 PersistenceListener configure(Config config)
          Initializes the HashDiskPersistenceListener.
protected  char[] getCacheFileName(String key)
          Generates a file name for the given cache key.
 
Methods inherited from class com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener
adjustFileCachePath, clear, getCacheFile, getCachePath, getContextTmpDir, getRoot, initFileCaching, isGroupStored, isStored, remove, remove, removeGroup, retrieve, retrieveGroup, store, store, storeGroup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIR_LEVELS

private static final int DIR_LEVELS
See Also:
Constant Field Values

HASH_ALGORITHM_KEY

public static final String HASH_ALGORITHM_KEY
See Also:
Constant Field Values

DEFAULT_HASH_ALGORITHM

public static final String DEFAULT_HASH_ALGORITHM
See Also:
Constant Field Values

md

protected MessageDigest md

PSEUDO

static final String[] PSEUDO
Constructor Detail

HashDiskPersistenceListener

public HashDiskPersistenceListener()
Method Detail

configure

public PersistenceListener configure(Config config)
Initializes the HashDiskPersistenceListener. Namely this involves only setting up the message digester to hash the key values.

Specified by:
configure in interface PersistenceListener
Overrides:
configure in class AbstractDiskPersistenceListener
Parameters:
config - The OSCache configuration
See Also:
PersistenceListener.configure(com.opensymphony.oscache.base.Config)

getCacheFileName

protected char[] getCacheFileName(String key)
Generates a file name for the given cache key. In this case the file name is attempted to be generated from the hash of the standard key name. Cache algorithm is configured via the cache.persistence.disk.hash.algorithm configuration variable.

Specified by:
getCacheFileName in class AbstractDiskPersistenceListener
Parameters:
key - cache entry key
Returns:
char[] file name

byteArrayToHexString

static String byteArrayToHexString(byte[] in)
Nibble conversion. Thanks to our friends at: http://www.devx.com/tips/Tip/13540

Parameters:
in - the byte array to convert
Returns:
a java.lang.String based version of they byte array


Copyright © 2011 OpenSymphony. All Rights Reserved.