java.lang.Object | |
↳ | android.support.v4.util.LruCache<K, V> |
Static library version of
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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Returns the number of times
create(Object)
returned a value.
|
||||||||||
|
Clear the cache, calling
entryRemoved(boolean, K, V, V)
on each removed entry.
|
||||||||||
|
Returns the number of values that have been evicted.
|
||||||||||
|
Returns the value for
key
if it exists in the cache or can be
created by
#create
.
|
||||||||||
|
Returns the number of times
get(K)
returned a value.
|
||||||||||
|
For caches that do not override
sizeOf(K, V)
, this returns the maximum
number of entries in the cache.
|
||||||||||
|
Returns the number of times
get(K)
returned null or required a new
value to be created.
|
||||||||||
|
Caches
value
for
key
.
|
||||||||||
|
Returns the number of times
put(K, V)
was called.
|
||||||||||
|
Removes the entry for
key
if it exists.
|
||||||||||
|
For caches that do not override
sizeOf(K, V)
, this returns the number
of entries in the cache.
|
||||||||||
|
Returns a copy of the current contents of the cache, ordered from least
recently accessed to most recently accessed.
|
||||||||||
|
Returns a string containing a concise, human-readable description of this
object.
|
||||||||||
|
Remove the eldest entries until the total of remaining entries is at or
below the requested size.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Called after a cache miss to compute a value for the corresponding key.
|
||||||||||
|
Called for entries that have been evicted or removed.
|
||||||||||
|
Returns the size of the entry for
key
and
value
in
user-defined units.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
maxSize |
for caches that do not override
sizeOf(K, V)
, this is
the maximum number of entries in the cache. For all other caches,
this is the maximum sum of the sizes of the entries in this cache.
|
---|
Returns the number of times
create(Object)
returned a value.
Clear the cache, calling
entryRemoved(boolean, K, V, V)
on each removed entry.
Returns the number of values that have been evicted.
Returns the value for
key
if 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.
For caches that do not override
sizeOf(K, V)
, this returns the maximum
number of entries in the cache. For all other caches, this returns the
maximum sum of the sizes of the entries in this cache.
Returns the number of times
get(K)
returned null or required a new
value to be created.
Caches
value
for
key
. The value is moved to the head of
the queue.
key
.
Removes the entry for
key
if it exists.
key
.
For caches that do not override
sizeOf(K, V)
, this returns the number
of entries in the cache. For all other caches, this returns the sum of
the sizes of the entries in this cache.
Returns a copy of the current contents of the cache, ordered from least recently accessed to most recently accessed.
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See
Writing a useful
toString
method
if you intend implementing your own
toString
method.
Remove the eldest entries until the total of remaining entries is at or below the requested size.
maxSize | the maximum size of the cache before returning. May be -1 to evict even 0-sized elements. |
---|
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.
The method is called without synchronization: other threads may access the cache while this method is executing.
If a value for
key
exists in the cache when this method
returns, the created value will be released with
entryRemoved(boolean, K, V, V)
and discarded. This can occur when multiple threads request the same key
at the same time (causing multiple values to be created), or when one
thread calls
put(K, V)
while another is creating a value for the same
key.
Called for entries that have been evicted or removed. This method is
invoked when a value is evicted to make space, removed by a call to
remove(K)
, or replaced by a call to
put(K, V)
. The default
implementation does nothing.
The method is called without synchronization: other threads may access the cache while this method is executing.
Returns the size of the entry for
key
and
value
in
user-defined units. The default implementation returns 1 so that size
is the number of entries and max size is the maximum number of entries.
An entry's size must not change while it is in the cache.