Package 

Class InMemoryLruCache


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

    • Method Summary

      Modifier and Type Method Description
      final Boolean add(String key, T value) Adds an object to the cache.
      final T get(String key) Retrieves an object from the cache.
      final T remove(String key) Removes an object from the cache.
      final Unit empty() Clears the entire cache, removing all cached objects.
      final Boolean isEmpty() Checks if the cache is empty.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • empty

         final Unit empty()

        Clears the entire cache, removing all cached objects.