K - The Key of the objects to cache.V - The Value of the objects to cache.@Status(stage=PRODUCTION, unitTests=PARTIAL) @Review(by="Kees Schotanus", at="2009-09-28") public class CCache<K,V> extends Object
LinkedHashMap which almost completely
creates an LRU cache. This CCache only adds some synchronization and some
statistics.LinkedHashMap| Constructor and Description |
|---|
CCache(int maximumSize)
Constructs a cache of the supplied maximumSize.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(K key,
V value)
Adds the supplied key/value pair to the cache.
|
void |
clear()
Clears the cache.
|
boolean |
containsKey(K key)
Determines whether the cache contains a value corresponding to the
supplied key.
|
V |
get(K key)
Gets the value corresponding to the supplied key from the cache.
|
double |
getCacheHitRatio()
Gets the cache/hit ratio.
|
String |
statisticsToString()
Creates a String representation of the statistics of this cache.
|
String |
toString()
Creates a String representation of this cache, consisting of all the
comma separated keys, within brackets.
|
public CCache(int maximumSize)
maximumSize - The maximum size of the cache.IllegalArgumentException - When the supplied maximumSize is less
than 2.public void add(K key, V value)
key - The key used to store the supplied value.value - The value to cache.NullPointerException - When either the supplied key or the supplied
value is null.public boolean containsKey(K key)
key - Key corresponding to the value to check for existence.public V get(K key)
key - Key corresponding to the value to get from the cache.public void clear()
public String toString()
public double getCacheHitRatio()
public String statisticsToString()
Copyright © 2008–2017. All rights reserved.