org.python.core.util
Class LimitedCache<K,V>
- java.lang.Object
-
- org.python.core.util.LimitedCache<K,V>
-
public class LimitedCache<K,V> extends java.lang.ObjectNot for application use, a cache of recently given results from some costly function. This is only public so we can reach it from the run-time. The user sets a nominal size for the cache. The cache will grow to this size and a little more, but from time to time discard the "little more" on the basis of a score that depends on recency of use.
-
-
Constructor Summary
Constructors Constructor and Description LimitedCache(int capacity)Construct a cache that will hold (at least) the specified number of entries.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(K key, V value)Add a value corresponding to a given key.Vget(K key)Get a value corresponding to the key, if it was previously cached.java.lang.StringtoString()
-
-
-
Constructor Detail
-
LimitedCache
public LimitedCache(int capacity)
Construct a cache that will hold (at least) the specified number of entries. (It will sometimes contain a few more so we don't have to scan the cache with every addition.)- Parameters:
capacity- the number of entries required
-
-
Method Detail
-
get
public V get(K key)
Get a value corresponding to the key, if it was previously cached.- Parameters:
key- against which cached- Returns:
- the cached value or
nullif not present
-
add
public void add(K key, V value)
Add a value corresponding to a given key.- Parameters:
key- against which to cache the valuevalue- to store
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG