|
||||||||||
| 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>
public abstract class AbstractDiskCache<K extends Serializable,V extends Serializable>
Abstract class providing a base implementation of a disk cache, which can be easily extended to implement a disk cache for a specific persistence mechanism.
When implementing the abstract methods note that while this base class handles most things, it does not acquire or release any locks. Implementations should do so as necessary. This is mainly done to minimize the time spent in critical sections.
Error handling in this class needs to be addressed. Currently if an exception is thrown by the persistence mechanism, this class destroys the event queue. Should it also destroy purgatory? Should it dispose itself?
| Nested Class Summary | |
|---|---|
protected class |
AbstractDiskCache.MyCacheListener
Cache that implements the CacheListener interface, and calls appropriate methods in its parent class. |
| Nested classes/interfaces inherited from interface org.apache.jcs.engine.behavior.ICacheType |
|---|
ICacheType.CacheType |
| Field Summary | |
|---|---|
protected boolean |
alive
Indicates whether the cache is 'alive': initialized, but not yet disposed. |
protected ICacheEventQueue<K,V> |
cacheEventQueue
The CacheEventQueue where changes will be queued for asynchronous updating of the persistent storage. |
protected String |
cacheName
Every cache will have a name, subclasses must set this when they are initialized. |
protected static org.apache.commons.logging.Log |
log
The logger |
protected Map<K,PurgatoryElement<K,V>> |
purgatory
Map where elements are stored between being added to this cache and actually spooled to disk. |
protected int |
purgHits
DEBUG: Keeps a count of the number of purgatory hits for debug messages |
protected ReentrantReadWriteLock |
removeAllLock
We lock here, so that we cannot get an update after a remove all. an individual removal locks the item. |
| Fields inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache |
|---|
cacheEventLogger, elementSerializer, keyMatcher |
| Constructor Summary | |
|---|---|
AbstractDiskCache(IDiskCacheAttributes attr)
Construct the abstract disk cache, create event queues and purgatory. |
|
| Method Summary | |
|---|---|
void |
dispose()
Adds a dispose request to the disk cache. |
protected void |
doDispose()
Dispose of the persistent store. |
protected ICacheElement<K,V> |
doGet(K key)
Get a value from the persistent store. |
protected Map<K,ICacheElement<K,V>> |
doGetMatching(String pattern)
Get a value from the persistent store. |
protected boolean |
doRemove(K key)
Remove an object from the persistent store if found. |
protected void |
doRemoveAll()
Remove all objects from the persistent store. |
protected void |
doUpdate(ICacheElement<K,V> cacheElement)
Add a cache element to the persistent store. |
ICacheElement<K,V> |
get(K key)
Check to see if the item is in purgatory. |
String |
getCacheName()
Returns the cache name. |
ICacheType.CacheType |
getCacheType()
Returns the cache type. |
protected abstract String |
getDiskLocation()
This is used by the event logging. |
String |
getEventLoggingExtraInfo()
Gets the extra info for the event log. |
abstract Set<K> |
getGroupKeys(String groupName)
The keys in a group. |
abstract Set<String> |
getGroupNames()
The group names in the cache. |
Map<K,ICacheElement<K,V>> |
getMatching(String pattern)
Gets items from the cache matching the given pattern. |
abstract int |
getSize()
Size cannot be determined without knowledge of the cache implementation, so subclasses will need to implement this method. |
IStats |
getStatistics()
Returns semi-structured data. |
String |
getStats()
Gets basic stats for the abstract disk cache. |
CacheStatus |
getStatus()
Returns the cache status. |
Map<K,ICacheElement<K,V>> |
processGetMultiple(Set<K> keys)
Gets multiple items from the cache based on the given set of keys. |
boolean |
remove(K key)
Removes are not queued. |
void |
removeAll()
Removes all from the region. |
void |
update(ICacheElement<K,V> cacheElement)
Adds the provided element to the cache. |
| Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging |
|---|
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, processDispose, processGet, processGetMatching, processRemove, processRemoveAll, processUpdate, 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 |
|---|
getAuxiliaryCacheAttributes, 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 Map<K extends Serializable,PurgatoryElement<K extends Serializable,V extends Serializable>> purgatory
If the elements are pulled into the memory cache while the are still in purgatory, writing to disk can be canceled.
protected ICacheEventQueue<K extends Serializable,V extends Serializable> cacheEventQueue
protected boolean alive
protected String cacheName
protected int purgHits
protected final ReentrantReadWriteLock removeAllLock
| Constructor Detail |
|---|
public AbstractDiskCache(IDiskCacheAttributes attr)
attr - | Method Detail |
|---|
public final void update(ICacheElement<K,V> cacheElement)
throws IOException
An update results in a put event being created. The put event will call the handlePut method defined here. The handlePut method calls the implemented doPut on the child.
update in interface ICache<K extends Serializable,V extends Serializable>update in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>cacheElement -
IOExceptionICache.update(org.apache.jcs.engine.behavior.ICacheElement) public final ICacheElement<K,V> get(K key)
get in interface ICache<K extends Serializable,V extends Serializable>get in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>key -
ICache.get(K)
public Map<K,ICacheElement<K,V>> getMatching(String pattern)
throws IOException
This only works with string keys. It's too expensive to do a toString on every key.
Auxiliaries will do their best to handle simple expressions. For instance, the JDBC disk cache will convert * to % and . to _
getMatching in interface ICache<K extends Serializable,V extends Serializable>getMatching in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>pattern -
IOExceptionpublic Map<K,ICacheElement<K,V>> processGetMultiple(Set<K> keys)
processGetMultiple in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>keys -
public abstract Set<K> getGroupKeys(String groupName)
getGroupKeys in interface AuxiliaryCache<K extends Serializable,V extends Serializable>AuxiliaryCache.getGroupKeys(java.lang.String)public abstract Set<String> getGroupNames()
getGroupNames in interface AuxiliaryCache<K extends Serializable,V extends Serializable>AuxiliaryCache.getGroupNames()
public final boolean remove(K key)
throws IOException
remove in interface ICache<K extends Serializable,V extends Serializable>remove in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>key -
IOExceptionICache.remove(K)
public final void removeAll()
throws IOException
AbstractAuxiliaryCacheEventLogging
removeAll in interface ICache<K extends Serializable,V extends Serializable>removeAll in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>IOExceptionICache.removeAll()
public final void dispose()
throws IOException
Disposal proceeds in several steps.
dispose in interface ICache<K extends Serializable,V extends Serializable>dispose in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>IOExceptionpublic String getCacheName()
ICache
getCacheName in interface ICache<K extends Serializable,V extends Serializable>ICache.getCacheName()public String getStats()
getStats in interface ICache<K extends Serializable,V extends Serializable>public IStats getStatistics()
getStatistics in interface AuxiliaryCache<K extends Serializable,V extends Serializable>AuxiliaryCache.getStatistics()public CacheStatus getStatus()
ICache
getStatus in interface ICache<K extends Serializable,V extends Serializable>ICache.getStatus()public abstract int getSize()
getSize in interface ICache<K extends Serializable,V extends Serializable>ICache.getSize()public ICacheType.CacheType getCacheType()
ICacheType
getCacheType in interface ICacheTypeICacheType.getCacheType()
protected final ICacheElement<K,V> doGet(K key)
throws IOException
Before the event logging layer, the subclasses implemented the do* methods. Now the do* methods call the *EventLogging method on the super. The *WithEventLogging methods call the abstract process* methods. The children implement the process methods.
key - Key to locate value for.
IOException
protected final Map<K,ICacheElement<K,V>> doGetMatching(String pattern)
throws IOException
Before the event logging layer, the subclasses implemented the do* methods. Now the do* methods call the *EventLogging method on the super. The *WithEventLogging methods call the abstract process* methods. The children implement the process methods.
pattern - Used to match keys.
IOException
protected final void doUpdate(ICacheElement<K,V> cacheElement)
throws IOException
Before the event logging layer, the subclasses implemented the do* methods. Now the do* methods call the *EventLogging method on the super. The *WithEventLogging methods call the abstract process* methods. The children implement the process methods.
cacheElement -
IOException
protected final boolean doRemove(K key)
throws IOException
Before the event logging layer, the subclasses implemented the do* methods. Now the do* methods call the *EventLogging method on the super. The *WithEventLogging methods call the abstract process* methods. The children implement the process methods.
key - Key of object to remove.
IOException
protected final void doRemoveAll()
throws IOException
Before the event logging layer, the subclasses implemented the do* methods. Now the do* methods call the *EventLogging method on the super. The *WithEventLogging methods call the abstract process* methods. The children implement the process methods.
IOException
protected final void doDispose()
throws IOException
Before the event logging layer, the subclasses implemented the do* methods. Now the do* methods call the *EventLogging method on the super. The *WithEventLogging methods call the abstract process* methods. The children implement the process methods.
IOExceptionpublic String getEventLoggingExtraInfo()
getEventLoggingExtraInfo in class AbstractAuxiliaryCache<K extends Serializable,V extends Serializable>protected abstract String getDiskLocation()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||