Package 

Class LruCountingMemoryCache

  • 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 class LruCountingMemoryCache<K, V>
     implements CountingMemoryCache<K, V>, MemoryCache<K, V>, HasDebugData
                        

    Layer of memory cache stack responsible for managing eviction of the the cached items.

    This layer is responsible for LRU 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.

    • 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.
      synchronized V inspect(K key)
      void probe(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.
      int removeAll(Predicate<K> predicate) Removes all the items from the cache whose key matches the specified predicate.
      void clear() Removes all the items from the cache.
      synchronized boolean contains(Predicate<K> predicate) Check if any items from the cache whose key matches the specified predicate.
      synchronized boolean contains(K key) Check if an item with the given cache key is currently in the cache.
      void trim(MemoryTrimType trimType) Trims the cache according to the specified trimming strategy and the given trim type.
      MemoryCacheParams getMemoryCacheParams()
      CountingLruMap<K, CountingMemoryCache.Entry<K, V>> getCachedEntries()
      Map<Bitmap, Object> getOtherEntries()
      void maybeEvictEntries() Removes the exclusively owned items until the cache constraints are met.
      synchronized int getCount() Gets the total number of all currently cached items.
      synchronized int getSizeInBytes() Gets the total size in bytes of all currently cached 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.
      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 String getDebugData()
      • Methods inherited from class com.facebook.imagepipeline.cache.CountingMemoryCache

        cache
      • 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
    • 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.

      • 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 this lock.

      • 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.