Package libcore.util
Class BasicLruCache<K,V>
- java.lang.Object
-
- libcore.util.BasicLruCache<K,V>
-
- Direct Known Subclasses:
TimeZoneNames.ZoneStringsCache
public class BasicLruCache<K,V> extends Object
A minimal least-recently-used cache for libcore. Preferandroid.util.LruCachewhere that is available.
-
-
Constructor Summary
Constructors Constructor Description BasicLruCache(int maxSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Vcreate(K key)Called after a cache miss to compute a value for the corresponding key.protected voidentryEvicted(K key, V value)Called for entries that have reached the tail of the least recently used queue and are be removed.voidevictAll()Clear the cache, callingentryEvicted(K, V)on each removed entry.Vget(K key)Returns the value forkeyif it exists in the cache or can be created by#create.Vput(K key, V value)Cachesvalueforkey.Map<K,V>snapshot()Returns a copy of the current contents of the cache, ordered from least recently accessed to most recently accessed.
-
-
-
Method Detail
-
get
public final V get(K key)
Returns the value forkeyif it exists in the cache or can be created by#create. If a value was returned, it is moved to the head of the queue. This returns null if a value is not cached and cannot be created.
-
put
public final V put(K key, V value)
Cachesvalueforkey. The value is moved to the head of the queue.- Returns:
- the previous value mapped by
key. Although that entry is no longer cached, it has not been passed toentryEvicted(K, V).
-
entryEvicted
protected void entryEvicted(K key, V value)
Called for entries that have reached the tail of the least recently used queue and are be removed. The default implementation does nothing.
-
create
protected V create(K key)
Called after a cache miss to compute a value for the corresponding key. Returns the computed value or null if no value can be computed. The default implementation returns null.
-
snapshot
public final Map<K,V> snapshot()
Returns a copy of the current contents of the cache, ordered from least recently accessed to most recently accessed.
-
evictAll
public final void evictAll()
Clear the cache, callingentryEvicted(K, V)on each removed entry.
-
-