-
public final class InMemoryLruCache<T extends Object>An in-memory LRU (Least Recently Used) cache implementation.
This class provides a simple way to cache objects in memory, using a configurable maximum size. It utilizes the LruCache class from the Android framework to manage the eviction of least recently used items.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classInMemoryLruCache.Companion
-
Constructor Summary
Constructors Constructor Description InMemoryLruCache(Integer maxSize, CacheMethods<T> memoryCache)
-
Method Summary
Modifier and Type Method Description final Booleanadd(String key, T value)Adds an object to the cache. final Tget(String key)Retrieves an object from the cache. final Tremove(String key)Removes an object from the cache. final Unitempty()Clears the entire cache, removing all cached objects. final BooleanisEmpty()Checks if the cache is empty. -
-
Constructor Detail
-
InMemoryLruCache
InMemoryLruCache(Integer maxSize, CacheMethods<T> memoryCache)
- Parameters:
maxSize- The maximum size of the cache in kilobytes.memoryCache- An optional implementation of CacheMethods for customizing the caching behavior.
-
-
Method Detail
-
add
final Boolean add(String key, T value)
Adds an object to the cache.
If the size of the object (in kilobytes) exceeds the maximum cache size, it will not be added, and any existing entry with the same key will be removed.
- Parameters:
key- The unique key associated with the object.value- The object to be cached.
-
get
final T get(String key)
Retrieves an object from the cache.
- Parameters:
key- The unique key associated with the object.
-
remove
final T remove(String key)
Removes an object from the cache.
- Parameters:
key- The unique key associated with the object.
-
-
-
-