|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object atg.nucleus.logging.VariableArgumentApplicationLoggingImpl atg.nucleus.GenericService atg.service.cache.Cache
public class Cache
This service is a general-purpose LRU cache.
Clients of this service must first implement CacheAdapter
,
which will be called by this class to maintain elements as related to
keys. The Cache class will then take care of maintaining the cache.
Most recent changes address multithreading problems. Specifically, when multiple threads are all requesting the object for a single key for the first time, the adapter is only asked to do the work once. Likewise, the same object is guaranteed to be returned to each thread in this scenario. Previously, if multiple threads all asked for an object that wasn't in cache and all used the same key, each thread would receive functionally similar but unique objects from the cache. This is a performance hit, and can also cause havoc with applications that expect all threads to receive a single object from cache.
Field Summary | |
---|---|
static java.lang.String |
CLASS_VERSION
|
Fields inherited from class atg.nucleus.GenericService |
---|
SERVICE_INFO_KEY |
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging |
---|
DEFAULT_LOG_TRACE_STATUS |
Fields inherited from interface atg.nucleus.logging.ApplicationLogging |
---|
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS |
Constructor Summary | |
---|---|
Cache()
Constructor |
Method Summary | |
---|---|
boolean |
contains(java.lang.Object pKey)
Checks for the presence of the object with the specified key, without invoking the CacheAdapter. |
boolean |
contains(java.lang.Object[] pKeys)
Returns false unless all specified keys refer to objects in the cache. |
java.lang.String |
dump()
|
void |
dump(java.io.PrintStream aStream)
meant to be a debugging aid, will print current key/value pairs the mMap hashtable to the supplied PrintStream, a prime example of which is System.out |
void |
flush()
Flushes all entries from the cache, leaving it empty. |
java.lang.Object |
get(java.lang.Object pKey)
Searches the cache for the object with the specified key. |
java.lang.Object[] |
get(java.lang.Object[] pKeys)
Searches the cache for the objects with the specified keys. |
int |
getAccessCount()
Returns the total number of accesses |
java.util.Iterator |
getAllElements()
Returns all elements in this Cache. |
java.util.Iterator |
getAllKeys()
Returns all elements in this Cache. |
java.util.Iterator |
getAllKeysOrdered(boolean pLatestFirst)
Returns all elements in this Cache ordered by entry creation time. |
CacheAdapter |
getCacheAdapter()
|
int |
getHitCount()
Returns the number of cache hits |
double |
getHitRatio()
Returns the number of cache hits / total number of cache accesses |
int |
getMaximumCacheEntries()
Returns the maximum number of elements in the cache. 0 = Cache nothing, but continue to get objects from the CacheAdapter -1 = Unlimited |
int |
getMaximumCacheSize()
Returns the maximum memory size of the cache. |
long |
getMaximumEntryLifetime()
Returns the maximum number of msec that an entry will live in the cache. 0 = Cache nothing, but continue to get objects from the CacheAdapter -1 = Unlimited |
int |
getMaximumEntrySize()
Returns the maximum memory size of a single entry in the cache. |
int |
getNumCacheEntries()
Returns the number of entries currently in the cache |
int |
getTimeoutCount()
Returns the number of times entries were invalidated because they were out-of-date. |
double |
getUsedCapacity()
Returns the ratio of cache entries to maximum cache entries. |
int |
getUsedMemory()
Returns the amount of memory taken up by the entries in the cache (includes keys). |
double |
getUsedMemoryCapacity()
Returns the ratio of memory size to maximum memory size |
java.util.Iterator |
getValidKeysOrdered(boolean pLatestFirst)
Returns all elements in this Cache ordered by entry creation time. |
protected boolean |
isExpiredValueStillGood(java.lang.Object key,
java.lang.Object pValue)
Return whether the expired value is still good. |
static void |
main(java.lang.String[] args)
|
void |
put(java.lang.Object pKey,
java.lang.Object pValue)
Puts an entry into the cache, placing that entry at the front of the LRU list. |
void |
remove(java.lang.Object pKey)
Invalidates the entry with the given key. |
void |
setCacheAdapter(CacheAdapter pAdapter)
The Adapter used to create entries in the cache |
void |
setMaximumCacheEntries(int pMaximumCacheEntries)
Sets the maximum number of elements in the cache. |
void |
setMaximumCacheSize(int pMaximumCacheSize)
Sets the maximum memory size of the cache. |
void |
setMaximumEntryLifetime(long pMaximumEntryLifetime)
Sets the maximum number of msec that an entry will live in the cache. 0 = Cache nothing, but continue to get objects from the CacheAdapter -1 = Unlimited |
void |
setMaximumEntrySize(int pMaximumEntrySize)
Sets the maximum memory size of a single entry in the cache. |
java.lang.Object |
setWaiterAndGetValue(java.lang.Object pKey,
boolean pCacheIt)
this method just gets an object from a cacheadapter, but in addition sets waiter semaphores to prevent the duplication of cache adapter work. |
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl |
---|
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String CLASS_VERSION
Constructor Detail |
---|
public Cache()
Method Detail |
---|
public java.lang.Object setWaiterAndGetValue(java.lang.Object pKey, boolean pCacheIt) throws java.lang.Exception
pKey
- the key to use for fetching from the CacheAdapterpCacheIt
- whether to put the object in the cache.
java.lang.Exception
public boolean contains(java.lang.Object pKey)
public boolean contains(java.lang.Object[] pKeys)
public void dump(java.io.PrintStream aStream)
public java.lang.String dump()
public java.lang.Object get(java.lang.Object pKey) throws java.lang.Exception
java.lang.Exception
public java.lang.Object[] get(java.lang.Object[] pKeys) throws java.lang.Exception
java.lang.Exception
protected boolean isExpiredValueStillGood(java.lang.Object key, java.lang.Object pValue)
pKey
- the key the corresponds to the valuepValue
- the value to checkpublic void put(java.lang.Object pKey, java.lang.Object pValue)
public void remove(java.lang.Object pKey)
public void flush()
public CacheAdapter getCacheAdapter()
public void setCacheAdapter(CacheAdapter pAdapter)
public int getMaximumCacheEntries()
public void setMaximumCacheEntries(int pMaximumCacheEntries)
public int getMaximumCacheSize()
public void setMaximumCacheSize(int pMaximumCacheSize)
public int getMaximumEntrySize()
public void setMaximumEntrySize(int pMaximumEntrySize)
public long getMaximumEntryLifetime()
public void setMaximumEntryLifetime(long pMaximumEntryLifetime)
public int getNumCacheEntries()
public double getUsedCapacity()
public int getUsedMemory()
public double getUsedMemoryCapacity()
public int getAccessCount()
public int getHitCount()
public double getHitRatio()
public int getTimeoutCount()
public java.util.Iterator getAllElements()
public java.util.Iterator getAllKeys()
public java.util.Iterator getValidKeysOrdered(boolean pLatestFirst)
public java.util.Iterator getAllKeysOrdered(boolean pLatestFirst)
public static void main(java.lang.String[] args) throws java.lang.InterruptedException
java.lang.InterruptedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |