Back to Fresco

LruCountingMemoryCache

docs/javadoc/reference/com/facebook/imagepipeline/cache/LruCountingMemoryCache.html

3.6.030.9 KB
Original Source

Fresco

|

|

Packages | Classes

Interfaces

Classes

Packages | Classes

Summary: Fields | Ctors | Methods | Inherited Methods | [Expand All]

public class

LruCountingMemoryCache

extends Object
implements HasDebugDataCountingMemoryCache<K, V> MemoryCache<K, V>

| java.lang.Object | | ↳ | com.facebook.imagepipeline.cache.LruCountingMemoryCache<K, V> |

Class Overview

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.

Summary

Fields
protected MemoryCacheParams
Public Constructors
Public Methods
CloseableReference<V>
Caches the given key-value pair.
CloseableReference<V>
Caches the given key-value pair.
void
Removes all the items from the cache.
synchronized boolean
Check if an item with the given cache key is currently in the cache.
synchronized boolean
Check if any items from the cache whose key matches the specified predicate.
CloseableReference<V>
Gets the item with the given key, or null if there is no such item.
CountingLruMap<K, Entry<K, V>>
synchronized int
Gets the total number of all currently cached items.
synchronized String
Return a string describing this object and to be used for debugging or logging
synchronized int
Gets the number of the exclusively owned items.
synchronized int
Gets the total size in bytes of the exclusively owned items.
synchronized int
Gets the number of the cached items that are used by at least one client.
synchronized int
Gets the total size in bytes of the cached items that are used by at least one client.
MemoryCacheParams
Map<Bitmap, Object>
synchronized int
Gets the total size in bytes of all currently cached items.
void
Removes the exclusively owned items until the cache constraints are met.
void
Probes whether the object corresponding to the key is in the cache.
int
Removes all the items from the cache whose key matches the specified predicate.
CloseableReference<V>
Gets the value with the given key to be reused, or null if there is no such value.
void
Trims the cache according to the specified trimming strategy and the given trim type.

| [Expand] Inherited Methods | | --- | | From class java.lang.Object

| Object | clone() | | boolean | equals(Object arg0) | | void | finalize() | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |

| | From interface com.facebook.cache.common.HasDebugData

| abstract String | getDebugData() Return a string describing this object and to be used for debugging or logging |

| | From interface com.facebook.common.memory.MemoryTrimmable

| abstract void | trim(MemoryTrimType trimType) Trim memory. |

| | From interface com.facebook.imagepipeline.cache.CountingMemoryCache

| abstract CloseableReference<V> | cache(K key, CloseableReference<V> valueRef, EntryStateObserver<K> observer) | | abstract void | clear() Removes all the items from the cache. | | abstract CountingLruMap<K, Entry<K, V>> | getCachedEntries() | | abstract int | getEvictionQueueCount() Gets the total size in bytes of the cached items that are used by at least one client. | | abstract int | getEvictionQueueSizeInBytes() Gets the total size in bytes of the exclusively owned items. | | abstract int | getInUseSizeInBytes() Gets the total size in bytes of the cached items that are used by at least one client. | | abstract MemoryCacheParams | getMemoryCacheParams() | | abstract Map<Bitmap, Object> | getOtherEntries() | | abstract void | maybeEvictEntries() Removes the exclusively owned items until the cache constraints are met. | | abstract CloseableReference<V> | reuse(K key) |

| | From interface com.facebook.imagepipeline.cache.MemoryCache

| abstract CloseableReference<V> | cache(K key, CloseableReference<V> value) Caches the the given key-value pair. | | abstract boolean | contains(K key) Check if the cache contains an item for the given key. | | abstract boolean | contains(Predicate<K> predicate) Find if any of the items from the cache whose keys match the specified predicate. | | abstract CloseableReference<V> | get(K key) Gets the item with the given key, or null if there is no such item. | | abstract int | getCount() Gets the total number of all currently cached items. | | abstract int | getSizeInBytes() Gets the total size in bytes of all currently cached items. | | abstract void | probe(K key) Probes whether the object corresponding to the key is in the cache. | | abstract int | removeAll(Predicate<K> predicate) Removes all the items from the cache whose keys match the specified predicate. |

|

Fields

protected MemoryCacheParams mMemoryCacheParams

Public Constructors

public LruCountingMemoryCache(ValueDescriptor<V> valueDescriptor, MemoryCache.CacheTrimStrategy cacheTrimStrategy, Supplier<MemoryCacheParams> memoryCacheParamsSupplier, EntryStateObserver<K> entryStateObserver)

Public Methods

public 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 is the caller's responsibility to close the returned reference once not needed anymore.

Returns
  • the new reference to be used, null if the value cannot be cached

public CloseableReference<V> cache(K key, CloseableReference<V> valueRef, EntryStateObserver<K> observer)

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.

Returns
  • the new reference to be used, null if the value cannot be cached

public void clear()

Removes all the items from the cache.

public 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 |

Returns
  • true is any items matches from the cache

public 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 |

Returns
  • true is any items matches from the cache

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

Returns
  • a reference to the cached value, or null if the item was not found

public CountingLruMap<K, Entry<K, V>> getCachedEntries()

public synchronized int getCount()

Gets the total number of all currently cached items.

public synchronized String getDebugData()

Return a string describing this object and to be used for debugging or logging

public synchronized int getEvictionQueueCount()

Gets the number of the exclusively owned items.

public synchronized int getEvictionQueueSizeInBytes()

Gets the total size in bytes of the exclusively owned items.

public synchronized int getInUseCount()

Gets the number of the cached items that are used by at least one client.

public synchronized int getInUseSizeInBytes()

Gets the total size in bytes of the cached items that are used by at least one client.

public MemoryCacheParams getMemoryCacheParams()

public Map<Bitmap, Object> getOtherEntries()

public synchronized int getSizeInBytes()

Gets the total size in bytes of all currently cached items.

public void maybeEvictEntries()

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.

public void probe(K key)

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.

public 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 |

Returns
  • number of the items removed from the cache

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

public void trim(MemoryTrimType trimType)

Trims the cache according to the specified trimming strategy and the given trim type.

+Generated by Doclava. +