public abstract class AbstractDiskCache<K,V> extends AbstractAuxiliaryCacheEventLogging<K,V> implements AuxiliaryCache<K,V>
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 | Class and Description |
|---|---|
protected class |
AbstractDiskCache.MyCacheListener
Cache that implements the CacheListener interface, and calls appropriate methods in its
parent class.
|
ICacheType.CacheType| Modifier and Type | Field and Description |
|---|---|
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 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.
|
| 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<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> |
getKeySet()
The keys 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.
|
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 Map<K,PurgatoryElement<K,V>> 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,V> cacheEventQueue
protected boolean alive
protected String cacheName
protected int purgHits
protected final ReentrantReadWriteLock removeAllLock
public AbstractDiskCache(IDiskCacheAttributes attr)
attr - 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,V>update in class AbstractAuxiliaryCacheEventLogging<K,V>cacheElement - IOExceptionICache.update(org.apache.commons.jcs.engine.behavior.ICacheElement<K, V>)public final ICacheElement<K,V> get(K key)
get in interface ICache<K,V>get in class AbstractAuxiliaryCacheEventLogging<K,V>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,V>getMatching in class AbstractAuxiliaryCacheEventLogging<K,V>pattern - IOExceptionpublic Map<K,ICacheElement<K,V>> processGetMultiple(Set<K> keys)
processGetMultiple in class AbstractAuxiliaryCacheEventLogging<K,V>keys - public abstract Set<K> getKeySet() throws IOException
getKeySet in interface AuxiliaryCache<K,V>IOException - if access to the auxiliary cache failsAuxiliaryCache.getKeySet()public final boolean remove(K key) throws IOException
remove in interface ICache<K,V>remove in class AbstractAuxiliaryCacheEventLogging<K,V>key - IOExceptionICache.remove(K)public final void removeAll()
throws IOException
AbstractAuxiliaryCacheEventLoggingremoveAll in interface ICache<K,V>removeAll in class AbstractAuxiliaryCacheEventLogging<K,V>IOExceptionICache.removeAll()public final void dispose()
throws IOException
Disposal proceeds in several steps.
dispose in interface ICache<K,V>dispose in class AbstractAuxiliaryCacheEventLogging<K,V>IOExceptionpublic String getCacheName()
ICachegetCacheName in interface ICache<K,V>ICache.getCacheName()public String getStats()
public IStats getStatistics()
getStatistics in interface AuxiliaryCache<K,V>AuxiliaryCache.getStatistics()public CacheStatus getStatus()
ICachegetStatus in interface ICache<K,V>ICache.getStatus()public abstract int getSize()
getSize in interface ICache<K,V>ICache.getSize()public ICacheType.CacheType getCacheType()
ICacheTypegetCacheType 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.IOExceptionprotected 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.IOExceptionprotected 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 - IOExceptionprotected 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.IOExceptionprotected 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.
IOExceptionprotected 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,V>protected abstract String getDiskLocation()
Copyright © 2002–2015 The Apache Software Foundation. All rights reserved.