public abstract class AbstractDiskCache extends AbstractAuxiliaryCacheEventLogging implements AuxiliaryCache, java.io.Serializable
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?
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
alive
Indicates whether the cache is 'alive': initialized, but not yet disposed.
|
protected ICacheEventQueue |
cacheEventQueue
The CacheEventQueue where changes will be queued for asynchronous updating of the persistent
storage.
|
protected java.lang.String |
cacheName
Every cache will have a name, subclasses must set this when they are initialized.
|
protected java.util.Map |
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
|
cacheEventLogger, elementSerializer, keyMatcherCACHE_HUB, DISK_CACHE, LATERAL_CACHE, REMOTE_CACHE| Constructor and Description |
|---|
AbstractDiskCache(IDiskCacheAttributes attr)
Construct the abstract disk cache, create event queues and purgatory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Adds a dispose request to the disk cache.
|
protected void |
doDispose()
Dispose of the persistent store.
|
protected ICacheElement |
doGet(java.io.Serializable key)
Get a value from the persistent store.
|
protected java.util.Map |
doGetMatching(java.lang.String pattern)
Get a value from the persistent store.
|
protected boolean |
doRemove(java.io.Serializable key)
Remove an object from the persistent store if found.
|
protected void |
doRemoveAll()
Remove all objects from the persistent store.
|
protected void |
doUpdate(ICacheElement cacheElement)
Add a cache element to the persistent store.
|
ICacheElement |
get(java.io.Serializable key)
Check to see if the item is in purgatory.
|
java.lang.String |
getCacheName()
Returns the cache name.
|
int |
getCacheType()
Returns the cache type.
|
protected abstract java.lang.String |
getDiskLocation()
This is used by the event logging.
|
java.lang.String |
getEventLoggingExtraInfo()
Gets the extra info for the event log.
|
abstract java.util.Set |
getGroupKeys(java.lang.String groupName)
The keys in a group.
|
java.util.Map |
getMatching(java.lang.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.
|
java.lang.String |
getStats()
Gets basic stats for the abstract disk cache.
|
int |
getStatus()
Returns the cache status.
|
java.util.Map |
processGetMultiple(java.util.Set keys)
Gets multiple items from the cache based on the given set of keys.
|
boolean |
remove(java.io.Serializable key)
Removes are not queued.
|
void |
removeAll()
Removes all from the region.
|
void |
update(ICacheElement cacheElement)
Adds the provided element to the cache.
|
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, processDispose, processGet, processGetMatching, processRemove, processRemoveAll, processUpdate, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLoggingcreateICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, setCacheEventLogger, setElementSerializer, setKeyMatcherclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAuxiliaryCacheAttributes, setCacheEventLogger, setElementSerializergetMultiple, setKeyMatcherprotected java.util.Map purgatory
If the elements are pulled into the memory cache while the are still in purgatory, writing to disk can be canceled.
protected ICacheEventQueue cacheEventQueue
protected boolean alive
protected java.lang.String cacheName
protected int purgHits
public AbstractDiskCache(IDiskCacheAttributes attr)
attr - public final void update(ICacheElement cacheElement) throws java.io.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 ICacheupdate in class AbstractAuxiliaryCacheEventLoggingcacheElement - java.io.IOExceptionICache.update(org.apache.jcs.engine.behavior.ICacheElement)public final ICacheElement get(java.io.Serializable key)
get in interface ICacheget in class AbstractAuxiliaryCacheEventLoggingkey - ICache.get(java.io.Serializable)public java.util.Map getMatching(java.lang.String pattern)
throws java.io.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 ICachegetMatching in class AbstractAuxiliaryCacheEventLoggingpattern - java.io.IOExceptionpublic java.util.Map processGetMultiple(java.util.Set keys)
processGetMultiple in class AbstractAuxiliaryCacheEventLoggingkeys - public abstract java.util.Set getGroupKeys(java.lang.String groupName)
(non-Javadoc)
getGroupKeys in interface AuxiliaryCacheAuxiliaryCache.getGroupKeys(java.lang.String)public final boolean remove(java.io.Serializable key)
throws java.io.IOException
remove in interface ICacheremove in class AbstractAuxiliaryCacheEventLoggingkey - java.io.IOExceptionICache.remove(java.io.Serializable)public final void removeAll()
throws java.io.IOException
AbstractAuxiliaryCacheEventLoggingremoveAll in interface ICacheremoveAll in class AbstractAuxiliaryCacheEventLoggingjava.io.IOExceptionICache.removeAll()public final void dispose()
throws java.io.IOException
Disposal proceeds in several steps.
dispose in interface ICachedispose in class AbstractAuxiliaryCacheEventLoggingjava.io.IOExceptionpublic java.lang.String getCacheName()
ICachegetCacheName in interface ICacheICache.getCacheName()public java.lang.String getStats()
public IStats getStatistics()
getStatistics in interface AuxiliaryCacheAuxiliaryCache.getStatistics()public int getStatus()
ICachegetStatus in interface ICacheICache.getStatus()public abstract int getSize()
getSize in interface ICacheICache.getSize()public int getCacheType()
ICacheTypegetCacheType in interface ICacheTypeICacheType.getCacheType()protected final ICacheElement doGet(java.io.Serializable key) throws java.io.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.java.io.IOExceptionprotected final java.util.Map doGetMatching(java.lang.String pattern)
throws java.io.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.java.io.IOExceptionprotected final void doUpdate(ICacheElement cacheElement) throws java.io.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 - java.io.IOExceptionprotected final boolean doRemove(java.io.Serializable key)
throws java.io.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.java.io.IOExceptionprotected final void doRemoveAll()
throws java.io.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.
java.io.IOExceptionprotected final void doDispose()
throws java.io.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.
java.io.IOExceptionpublic java.lang.String getEventLoggingExtraInfo()
getEventLoggingExtraInfo in class AbstractAuxiliaryCacheprotected abstract java.lang.String getDiskLocation()
Copyright © 2002-2013 Apache Software Foundation. All Rights Reserved.