-
- All Implemented Interfaces:
-
com.facebook.cache.common.HasDebugData,com.facebook.common.memory.MemoryTrimmable,com.facebook.imagepipeline.cache.CountingMemoryCache,com.facebook.imagepipeline.cache.MemoryCache
@ThreadSafe() public abstract class AbstractAdaptiveCountingMemoryCache<K, V> implements CountingMemoryCache<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.
-
-
Constructor Summary
Constructors Constructor Description AbstractAdaptiveCountingMemoryCache(Supplier<MemoryCacheParams> memoryCacheParamsSupplier, MemoryCache.CacheTrimStrategy cacheTrimStrategy, ValueDescriptor<V> valueDescriptor, int adaptiveRatePromil, int frequentlyUsedThreshold, int ghostListMaxSize, int lfuFractionPromil)
-
Method Summary
Modifier and Type Method Description CloseableReference<V>cache(K key, CloseableReference<V> valueRef)Caches the given key-value pair. CloseableReference<V>cache(K key, CloseableReference<V> valueRef, @Nullable() CountingMemoryCache.EntryStateObserver<K> observer)Caches the given key-value pair. CloseableReference<V>get(K key)Gets the item with the given key, or null if there is no such item. Vinspect(K key)voidprobe(K key)Probes whether the object corresponding to the key is in the cache. CloseableReference<V>reuse(K key)Gets the value with the given key to be reused, or null if there is no such value. intremoveAll(Predicate<K> predicate)Removes all the items from the cache whose key matches the specified predicate. voidclear()Removes all the items from the cache. synchronized booleancontains(Predicate<K> predicate)Check if any items from the cache whose key matches the specified predicate. synchronized booleancontains(K key)Check if an item with the given cache key is currently in the cache. voidtrim(MemoryTrimType trimType)Trims the cache according to the specified trimming strategy and the given trim type. MemoryCacheParamsgetMemoryCacheParams()voidmaybeEvictEntries()Removes the exclusively owned items until the cache constraints are met. synchronized intgetCount()Gets the total number of all currently cached items. synchronized intgetSizeInBytes()Gets the total size in bytes of all currently cached items. synchronized intgetInUseCount()Gets the number of the cached items that are used by at least one client. synchronized intgetInUseSizeInBytes()Gets the total size in bytes of the cached items that are used by at least one client. synchronized intgetEvictionQueueCount()Gets the number of the exclusively owned items. synchronized intgetEvictionQueueSizeInBytes()Gets the total size in bytes of the exclusively owned items. StringreportData()CountingLruMapgetCachedEntries()Map<Bitmap, Object>getOtherEntries()-
Methods inherited from class com.facebook.imagepipeline.cache.CountingMemoryCache
cache, getCachedEntries -
Methods inherited from class com.facebook.imagepipeline.cache.MemoryCache
cache, contains, get, getCount, getSizeInBytes, inspect, probe, removeAll -
Methods inherited from class com.facebook.common.memory.MemoryTrimmable
trim -
Methods inherited from class com.facebook.cache.common.HasDebugData
getDebugData -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
AbstractAdaptiveCountingMemoryCache
AbstractAdaptiveCountingMemoryCache(Supplier<MemoryCacheParams> memoryCacheParamsSupplier, MemoryCache.CacheTrimStrategy cacheTrimStrategy, ValueDescriptor<V> valueDescriptor, int adaptiveRatePromil, int frequentlyUsedThreshold, int ghostListMaxSize, int lfuFractionPromil)
-
-
Method Detail
-
cache
@Nullable() CloseableReference<V> cache(K key, CloseableReference<V> valueRef)
Caches the given key-value pair.
Important: the client should use the returned reference instead of the original one. It isthe caller's responsibility to close the returned reference once not needed anymore.
-
cache
@Nullable() CloseableReference<V> cache(K key, CloseableReference<V> valueRef, @Nullable() CountingMemoryCache.EntryStateObserver<K> observer)
Caches the given key-value pair.
Important: the client should use the returned reference instead of the original one. It isthe caller's responsibility to close the returned reference once not needed anymore.
-
get
@Nullable() CloseableReference<V> get(K key)
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.
-
probe
void probe(K key)
Probes whether the object corresponding to the key is in the cache. Note that the act ofprobing touches the item (if present in cache), thus changing its LRU timestamp.
-
reuse
@Nullable() CloseableReference<V> reuse(K key)
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.
-
removeAll
int removeAll(Predicate<K> predicate)
Removes all the items from the cache whose key matches the specified predicate.
- Parameters:
predicate- returns true if an item with the given key should be removed
-
clear
void clear()
Removes all the items from the cache.
-
contains
synchronized boolean contains(Predicate<K> predicate)
Check if any items from the cache whose key matches the specified predicate.
- Parameters:
predicate- returns true if an item with the given key matches
-
contains
synchronized boolean contains(K key)
Check if an item with the given cache key is currently in the cache.
- Parameters:
key- returns true if an item with the given key matches
-
trim
void trim(MemoryTrimType trimType)
Trims the cache according to the specified trimming strategy and the given trim type. We firsttrim the LFU cache, if we need to trim more, we continue to trim the MFU cache.
-
getMemoryCacheParams
MemoryCacheParams getMemoryCacheParams()
-
maybeEvictEntries
void maybeEvictEntries()
Removes the exclusively owned items until the cache constraints are met.
This method invokes the external close method, so it must not becalled while holding the
thislock.
-
getCount
synchronized int getCount()
Gets the total number of all currently cached items.
-
getSizeInBytes
synchronized int getSizeInBytes()
Gets the total size in bytes of all currently cached items.
-
getInUseCount
synchronized int getInUseCount()
Gets the number of the cached items that are used by at least one client.
-
getInUseSizeInBytes
synchronized int getInUseSizeInBytes()
Gets the total size in bytes of the cached items that are used by at least one client.
-
getEvictionQueueCount
synchronized int getEvictionQueueCount()
Gets the number of the exclusively owned items.
-
getEvictionQueueSizeInBytes
synchronized int getEvictionQueueSizeInBytes()
Gets the total size in bytes of the exclusively owned items.
-
reportData
String reportData()
-
getCachedEntries
CountingLruMap getCachedEntries()
-
getOtherEntries
Map<Bitmap, Object> getOtherEntries()
-
-
-
-