Package org.apache.jackrabbit.core.cache
Class AbstractCache
- java.lang.Object
-
- org.apache.jackrabbit.core.cache.AbstractCache
-
- All Implemented Interfaces:
Cache
- Direct Known Subclasses:
ConcurrentCache
public abstract class AbstractCache extends Object implements Cache
Abstract base class for managedCaches. This class uses atomic variables to track the current and maximum size of the cache, the cache access count and a possibleCacheAccessListenerinstance.A subclass should call the protected
recordCacheAccess()method whenever the cache is accessed (even cache misses should be reported). The subclass should also use therecordSizeChange(long)method to record all changes in the cache size, and automatically evict excess items when theisTooBig()method returnstrue.
-
-
Constructor Summary
Constructors Constructor Description AbstractCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()longgetAccessCount()Get the number of accesses (get or set) until resetAccessCount was called.StringgetCacheInfoAsString()Gathers the stats of the cache for logging.longgetMaxMemorySize()Get the current limit.longgetMemoryUsed()Get the amount of used memory.longgetMissCount()Get the number of cache misses.longgetTotalAccessCount()Get the total number of cache accesses.protected booleanisTooBig()Checks whether the current estimate of the amount of memory used by this cache exceeds the allocated maximum amount of memory.protected voidrecordCacheAccess()Records a single cache access and calls the configuredCacheAccessListener(if any) whenever the constant access interval has passed since the previous listener call.protected voidrecordCacheMiss()protected voidrecordSizeChange(long delta)Updates the current memory use estimate of this cache.voidresetAccessCount()Reset the access counter.voidresetMissCount()Reset the cache miss counter.voidsetAccessListener(CacheAccessListener listener)Set the cache access listener.voidsetMaxMemorySize(long size)Set the new memory limit.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.jackrabbit.core.cache.Cache
getElementCount
-
-
-
-
Method Detail
-
isTooBig
protected boolean isTooBig()
Checks whether the current estimate of the amount of memory used by this cache exceeds the allocated maximum amount of memory.- Returns:
trueif the cache size is too big,falseotherwise
-
recordSizeChange
protected void recordSizeChange(long delta)
Updates the current memory use estimate of this cache.- Parameters:
delta- number of bytes added or removed
-
recordCacheAccess
protected void recordCacheAccess()
Records a single cache access and calls the configuredCacheAccessListener(if any) whenever the constant access interval has passed since the previous listener call.
-
recordCacheMiss
protected void recordCacheMiss()
-
getAccessCount
public long getAccessCount()
Description copied from interface:CacheGet the number of accesses (get or set) until resetAccessCount was called.- Specified by:
getAccessCountin interfaceCache- Returns:
- the count
-
resetAccessCount
public void resetAccessCount()
Description copied from interface:CacheReset the access counter.- Specified by:
resetAccessCountin interfaceCache
-
getTotalAccessCount
public long getTotalAccessCount()
Description copied from interface:CacheGet the total number of cache accesses.- Specified by:
getTotalAccessCountin interfaceCache- Returns:
- the number of hits
-
getMissCount
public long getMissCount()
Description copied from interface:CacheGet the number of cache misses.- Specified by:
getMissCountin interfaceCache- Returns:
- the number of misses
-
resetMissCount
public void resetMissCount()
Description copied from interface:CacheReset the cache miss counter.- Specified by:
resetMissCountin interfaceCache
-
getMemoryUsed
public long getMemoryUsed()
Description copied from interface:CacheGet the amount of used memory.- Specified by:
getMemoryUsedin interfaceCache- Returns:
- the size in bytes
-
getMaxMemorySize
public long getMaxMemorySize()
Description copied from interface:CacheGet the current limit.- Specified by:
getMaxMemorySizein interfaceCache- Returns:
- the size in bytes
-
setMaxMemorySize
public void setMaxMemorySize(long size)
Description copied from interface:CacheSet the new memory limit.- Specified by:
setMaxMemorySizein interfaceCache- Parameters:
size- the size in bytes
-
setAccessListener
public void setAccessListener(CacheAccessListener listener)
Set the cache access listener. Only one listener per cache is supported.- Specified by:
setAccessListenerin interfaceCache- Parameters:
listener- the new listener
-
dispose
public void dispose()
-
getCacheInfoAsString
public String getCacheInfoAsString()
Gathers the stats of the cache for logging.- Specified by:
getCacheInfoAsStringin interfaceCache
-
-