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. Prefer
android.util.LruCache where that is available.-
Constructor Summary
Constructors Constructor Description BasicLruCache(int maxSize) -
Method Summary
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.
-
Constructor Details
-
BasicLruCache
public BasicLruCache(int maxSize)
-
-
Method Details
-
get
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
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
Called for entries that have reached the tail of the least recently used queue and are be removed. The default implementation does nothing. -
create
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
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.
-