Interface MemoryCache
- All Known Implementing Classes:
LruResourceCache,MemoryCacheAdapter
public interface MemoryCache
An interface for adding and removing resources from an in memory cache.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn interface that will be called whenever a bitmap is removed from the cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidEvict all items from the memory cache.longReturns the sum of the sizes of all the contents of the cache in bytes.longReturns the current maximum size in bytes of the cache.Resource<?>Add bitmap to the cache with the given key.Resource<?>Removes the value for the given key and returns it if present or null otherwise.voidSet the listener to be called when a bitmap is removed from the cache.voidsetSizeMultiplier(float multiplier) Adjust the maximum size of the cache by multiplying the original size of the cache by the given multiplier.voidtrimMemory(int level) Trim the memory cache to the appropriate level.
-
Method Details
-
getCurrentSize
long getCurrentSize()Returns the sum of the sizes of all the contents of the cache in bytes. -
getMaxSize
long getMaxSize()Returns the current maximum size in bytes of the cache. -
setSizeMultiplier
void setSizeMultiplier(float multiplier) Adjust the maximum size of the cache by multiplying the original size of the cache by the given multiplier.If the size multiplier causes the size of the cache to be decreased, items will be evicted until the cache is smaller than the new size.
- Parameters:
multiplier- A size multiplier>= 0.
-
remove
Removes the value for the given key and returns it if present or null otherwise.- Parameters:
key- The key.
-
put
Add bitmap to the cache with the given key.- Parameters:
key- The key to retrieve the bitmap.resource- Thecom.bumptech.glide.load.engine.EngineResource<Z>to store.- Returns:
- The old value of key (null if key is not in map).
-
setResourceRemovedListener
Set the listener to be called when a bitmap is removed from the cache.- Parameters:
listener- The listener.
-
clearMemory
void clearMemory()Evict all items from the memory cache. -
trimMemory
void trimMemory(int level) Trim the memory cache to the appropriate level. Typically called on the callback onTrimMemory.- Parameters:
level- This integer represents a trim level as specified inComponentCallbacks2.
-