LruCache

public class LruCache
extends Object

java.lang.Object
   ↳ android.support.v4.util.LruCache<K, V>


Static library version of android.util.LruCache. Used to write apps that run on API levels prior to 12. When running on API level 12 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Summary

Public constructors

LruCache(int maxSize)

Public methods

final int createCount()

Returns the number of times create(Object) returned a value.

final void evictAll()

Clear the cache, calling entryRemoved(boolean, K, V, V) on each removed entry.

final int evictionCount()

Returns the number of values that have been evicted.

final V get(K key)

Returns the value for key if it exists in the cache or can be created by #create.

final int hitCount()

Returns the number of times get(K) returned a value that was already present in the cache.

final int maxSize()

For caches that do not override sizeOf(K, V), this returns the maximum number of entries in the cache.

final int missCount()

Returns the number of times get(K) returned null or required a new value to be created.

final V put(K key, V value)

Caches value for key.

final int putCount()

Returns the number of times put(K, V) was called.

final V remove(K key)

Removes the entry for key if it exists.

void resize(int maxSize)

Sets the size of the cache.

final int size()

For caches that do not override sizeOf(K, V), this returns the number of entries in the cache.

final Map<K, V> snapshot()

Returns a copy of the current contents of the cache, ordered from least recently accessed to most recently accessed.

final String toString()
void trimToSize(int maxSize)

Remove the eldest entries until the total of remaining entries is at or below the requested size.

Protected methods

V create(K key)

Called after a cache miss to compute a value for the corresponding key.

void entryRemoved(boolean evicted, K key, V oldValue, V newValue)

Called for entries that have been evicted or removed.

int sizeOf(K key, V value)

Returns the size of the entry for key and value in user-defined units.

Inherited methods