java.lang.Object | |
↳ | com.facebook.imagepipeline.cache.AbstractAdaptiveCountingMemoryCache<K, V> |
Layer of memory cache stack responsible for managing eviction of the the cached items.
This layer is responsible for Adaptive Replacement Cache (ARC) eviction strategy and for maintaining the size boundaries of the cached items.
Only the exclusively owned elements, i.e. the elements not referenced by any client, can be evicted.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
protected MemoryCacheParams | mMemoryCacheParams |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AbstractAdaptiveCountingMemoryCache(Supplier<MemoryCacheParams> memoryCacheParamsSupplier, MemoryCache.CacheTrimStrategy cacheTrimStrategy, ValueDescriptor<V> valueDescriptor, int adaptiveRatePromil, int frequentlyUsedThreshold, int ghostListMaxSize, int lfuFractionPromil) |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CloseableReference<V> |
cache(K key, CloseableReference<V> valueRef)
Caches the given key-value pair.
| ||||||||||
CloseableReference<V> |
cache(K key, CloseableReference<V> valueRef, EntryStateObserver<K> observer)
Caches the given key-value pair.
| ||||||||||
void |
clear()
Removes all the items from the cache.
| ||||||||||
synchronized boolean |
contains(K key)
Check if an item with the given cache key is currently in the cache.
| ||||||||||
synchronized boolean |
contains(Predicate<K> predicate)
Check if any items from the cache whose key matches the specified predicate.
| ||||||||||
CloseableReference<V> |
get(K key)
Gets the item with the given key, or null if there is no such item.
| ||||||||||
CountingLruMap | getCachedEntries() | ||||||||||
synchronized int |
getCount()
Gets the total number of all currently cached items.
| ||||||||||
synchronized int |
getEvictionQueueCount()
Gets the number of the exclusively owned items.
| ||||||||||
synchronized int |
getEvictionQueueSizeInBytes()
Gets the total size in bytes of the exclusively owned items.
| ||||||||||
synchronized int |
getInUseCount()
Gets the number of the cached items that are used by at least one client.
| ||||||||||
synchronized int |
getInUseSizeInBytes()
Gets the total size in bytes of the cached items that are used by at least one client.
| ||||||||||
MemoryCacheParams | getMemoryCacheParams() | ||||||||||
Map<Bitmap, Object> | getOtherEntries() | ||||||||||
synchronized int |
getSizeInBytes()
Gets the total size in bytes of all currently cached items.
| ||||||||||
void |
maybeEvictEntries()
Removes the exclusively owned items until the cache constraints are met.
| ||||||||||
void |
probe(K key)
Probes whether the object corresponding to the key is in the cache.
| ||||||||||
int |
removeAll(Predicate<K> predicate)
Removes all the items from the cache whose key matches the specified predicate.
| ||||||||||
String | reportData() | ||||||||||
CloseableReference<V> |
reuse(K key)
Gets the value with the given key to be reused, or null if there is no such value.
| ||||||||||
void |
trim(MemoryTrimType trimType)
Trims the cache according to the specified trimming strategy and the given trim type.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract void | logIllegalAdaptiveRate() | ||||||||||
abstract void | logIllegalLfuFraction() |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
com.facebook.cache.common.HasDebugData
| |||||||||||
From interface
com.facebook.common.memory.MemoryTrimmable
| |||||||||||
From interface
com.facebook.imagepipeline.cache.CountingMemoryCache
| |||||||||||
From interface
com.facebook.imagepipeline.cache.MemoryCache
|
Caches the given key-value pair.
Important: the client should use the returned reference instead of the original one. It is the caller's responsibility to close the returned reference once not needed anymore.
Caches the given key-value pair.
Important: the client should use the returned reference instead of the original one. It is the caller's responsibility to close the returned reference once not needed anymore.
Removes all the items from the cache.
Check if an item with the given cache key is currently in the cache.
key | returns true if an item with the given key matches |
---|
Check if any items from the cache whose key matches the specified predicate.
predicate | returns true if an item with the given key matches |
---|
Gets the item with the given key, or null if there is no such item.
It is the caller's responsibility to close the returned reference once not needed anymore.
Gets the total number of all currently cached items.
Gets the number of the exclusively owned items.
Gets the total size in bytes of the exclusively owned items.
Gets the number of the cached items that are used by at least one client.
Gets the total size in bytes of the cached items that are used by at least one client.
Gets the total size in bytes of all currently cached items.
Removes the exclusively owned items until the cache constraints are met.
This method invokes the external close()
method, so it must not be
called while holding the this
lock.
Probes whether the object corresponding to the key is in the cache. Note that the act of probing touches the item (if present in cache), thus changing its LRU timestamp.
Removes all the items from the cache whose key matches the specified predicate.
predicate | returns true if an item with the given key should be removed |
---|
Gets the value with the given key to be reused, or null if there is no such value.
The item can be reused only if it is exclusively owned by the cache.
Trims the cache according to the specified trimming strategy and the given trim type. We first trim the LFU cache, if we need to trim more, we continue to trim the MFU cache.