Package uk.num.numlib.internal.util
Class SimpleCache<K,V>
java.lang.Object
uk.num.numlib.internal.util.SimpleCache<K,V>
- Type Parameters:
K- The class that the keys will be instances of.V- The class that the values will be instances of.
public final class SimpleCache<K,V>
extends java.lang.Object
A very basic cache with a timeout mechanism.
-
Constructor Summary
Constructors Constructor Description SimpleCache()Default Constructor -
Method Summary
-
Constructor Details
-
SimpleCache
public SimpleCache()Default Constructor
-
-
Method Details
-
setTimeToLive
public void setTimeToLive(int millis)Override the default cache timeout. Can be set at any time but only affects items cached after the value is set.- Parameters:
millis- The number of milliseconds until the cached item should be considered stale.
-
put
Add an item to the cache.- Parameters:
key- The key of class Kvalue- The value of class V
-
get
Get an item from the cache.- Parameters:
key- The key of class K- Returns:
- null if the item is not present or has expired, otherwise the value of class V
-