public abstract class AbstractCache extends Object implements Cache
Caches. This class uses atomic
 variables to track the current and maximum size of the cache, the cache
 access count and a possible CacheAccessListener instance.
 
 A subclass should call the protected recordCacheAccess() method
 whenever the cache is accessed (even cache misses should be reported).
 The subclass should also use the recordSizeChange(long) method
 to record all changes in the cache size, and automatically evict excess
 items when the isTooBig() method returns true.
| Constructor and Description | 
|---|
| AbstractCache() | 
| Modifier and Type | Method and Description | 
|---|---|
| void | dispose() | 
| long | getAccessCount()Get the number of accesses (get or set) until resetAccessCount was called. | 
| String | getCacheInfoAsString()Gathers the stats of the cache for logging. | 
| long | getMaxMemorySize()Get the current limit. | 
| long | getMemoryUsed()Get the amount of used memory. | 
| long | getMissCount()Get the number of cache misses. | 
| long | getTotalAccessCount()Get the total number of cache accesses. | 
| protected boolean | isTooBig()Checks whether the current estimate of the amount of memory used
 by this cache exceeds the allocated maximum amount of memory. | 
| protected void | recordCacheAccess()Records a single cache access and calls the configured
  CacheAccessListener(if any) whenever the constant access
 interval has passed since the previous listener call. | 
| protected void | recordCacheMiss() | 
| protected void | recordSizeChange(long delta)Updates the current memory use estimate of this cache. | 
| void | resetAccessCount()Reset the access counter. | 
| void | resetMissCount()Reset the cache miss counter. | 
| void | setAccessListener(CacheAccessListener listener)Set the cache access listener. | 
| void | setMaxMemorySize(long size)Set the new memory limit. | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetElementCountprotected boolean isTooBig()
true if the cache size is too big,
         false otherwiseprotected void recordSizeChange(long delta)
delta - number of bytes added or removedprotected void recordCacheAccess()
CacheAccessListener (if any) whenever the constant access
 interval has passed since the previous listener call.protected void recordCacheMiss()
public long getAccessCount()
CachegetAccessCount in interface Cachepublic void resetAccessCount()
CacheresetAccessCount in interface Cachepublic long getTotalAccessCount()
CachegetTotalAccessCount in interface Cachepublic long getMissCount()
CachegetMissCount in interface Cachepublic void resetMissCount()
CacheresetMissCount in interface Cachepublic long getMemoryUsed()
CachegetMemoryUsed in interface Cachepublic long getMaxMemorySize()
CachegetMaxMemorySize in interface Cachepublic void setMaxMemorySize(long size)
CachesetMaxMemorySize in interface Cachesize - the size in bytespublic void setAccessListener(CacheAccessListener listener)
setAccessListener in interface Cachelistener - the new listenerpublic void dispose()
public String getCacheInfoAsString()
getCacheInfoAsString in interface CacheCopyright © 2004–2022 The Apache Software Foundation. All rights reserved.