Class WSLruCache
java.lang.Object
com.webmethods.caf.wsclient.cache.impl.WSLruCache
Fixed length cache with a LRU replacement policy. If cache items
implement CacheListener, they will be informed when they're removed
from the cache.
Null keys are not allowed. WSLruCache is synchronized.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected long
-
Constructor Summary
ConstructorsConstructorDescriptionWSLruCache
(int maxCapacity, long maxFreshTimeout) Create the LRU cache with a specific capacity and freshness timeout. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears all entries from the cacheboolean
containsKey
(Object key) Determines if an item is in the CacheGet an item from the cache and make it most recently used.protected Object
Get an item from the hash and return it.Returns the fresh keys stored in the cache Note: this is a snapshot of the keys and is therefore safe to iterate, however care needs to be taken when using these keys for cache lookups as the key may no longer exist.Iterator<com.webmethods.caf.wsclient.cache.impl.WSLruCache.CacheItem>
Returns the values stored in the cache Note: this is a snapshot of the values and is therefore safe to iterate but may not reflect the current state of the cache.getKeys()
Get an iterator for the keys of the cache, including both fresh and stale entries Note: this is a snapshot of the keys and is therefore safe to iterate, however care needs to be taken when using these keys for cache lookups as the key may no longer exist.int
The current capacity of this cacheIterator<com.webmethods.caf.wsclient.cache.impl.WSLruCache.CacheItem>
Get an iterator for the values of the cache that includes both stale and fresh enties Note: this is a snapshot of the values and is therefore safe to iterate but may not reflect the current state of the cache.protected void
Puts a new item in the cache and returns the previous value stored under that keyRemoves an item from the cacheint
size()
The current size of the cache
-
Field Details
-
m_cacheMap
-
m_cacheCapacity
protected int m_cacheCapacity -
m_entryTimeout
protected long m_entryTimeout
-
-
Constructor Details
-
WSLruCache
public WSLruCache(int maxCapacity, long maxFreshTimeout) Create the LRU cache with a specific capacity and freshness timeout. Entries older than a specific staleness will act as a cache miss.- Parameters:
maxCapacity
- - minimum capacity of the cachemaxCapacity
- - maximum cache entry age (in milliseconds)
-
-
Method Details
-
clear
public void clear()Clears all entries from the cache -
size
public int size()The current size of the cache- Returns:
- the current queue size as int
-
getMaxCapacity
public int getMaxCapacity()The current capacity of this cache- Returns:
- the queue capacity
-
containsKey
Determines if an item is in the Cache- Parameters:
key
- the unique key to the item in the cache- Returns:
- true if the cache contains an entry for the given key
-
get
Get an item from the cache and make it most recently used.- Parameters:
key
- key to lookup the item- Returns:
- the matching object in the cache
-
getFresh
Get an item from the hash and return it. If the item is stale, it is removed from the hash and null is returned.- Parameters:
key
- - the cache key object- Returns:
- the fresh cache entry if found, otherwise null
-
put
Puts a new item in the cache and returns the previous value stored under that key- Parameters:
key
- key to store datavalue
- value to be stored- Returns:
- old value stored under the key
-
remove
Removes an item from the cache- Parameters:
key
- the key to remove- Returns:
- the value removed
-
getKeys
Get an iterator for the keys of the cache, including both fresh and stale entries Note: this is a snapshot of the keys and is therefore safe to iterate, however care needs to be taken when using these keys for cache lookups as the key may no longer exist.- Returns:
- an Iterator containing the cache keys as Objects
-
getFreshKeys
Returns the fresh keys stored in the cache Note: this is a snapshot of the keys and is therefore safe to iterate, however care needs to be taken when using these keys for cache lookups as the key may no longer exist.- Returns:
- an Iterator containing those cache keys that have not expired as Objects
-
getValues
Get an iterator for the values of the cache that includes both stale and fresh enties Note: this is a snapshot of the values and is therefore safe to iterate but may not reflect the current state of the cache.- Returns:
- an Iterator of cache value as CacheItem objects
-
getFreshValues
Returns the values stored in the cache Note: this is a snapshot of the values and is therefore safe to iterate but may not reflect the current state of the cache.- Returns:
- an Iterator of cache values that have not expired as CacheItem objects
-
printCacheToConsole
protected void printCacheToConsole()
-