Class LRUCache

All Implemented Interfaces:
Serializable, Cloneable, Map, Cache
Direct Known Subclasses:
AbstractCachingDictionary.ObservableCache

public class LRUCache extends LinkedHashMap implements Cache
A fixed-capacity Cache that stores the most recently used elements. Once the cache reaches capacity, the least recently used elements will be removed.
See Also:
  • Field Details

    • _capacity

      private int _capacity
  • Constructor Details

    • LRUCache

      public LRUCache(int capacity)
      Parameters:
      capacity - the maximum number of elements that can be contained in the cache.
  • Method Details

    • isFull

      public boolean isFull()
    • removeEldestEntry

      protected boolean removeEldestEntry(Map.Entry eldest)
      Overrides:
      removeEldestEntry in class LinkedHashMap
    • setCapacity

      public int setCapacity(int capacity)
      Description copied from interface: Cache
      Set the maximum number of elements the cache can hold.
      Specified by:
      setCapacity in interface Cache
    • getCapacity

      public int getCapacity()
      Description copied from interface: Cache
      Returns the maximum number of elements the cache can hold.
      Specified by:
      getCapacity in interface Cache
    • getSize

      public int getSize()
      Description copied from interface: Cache
      Returns the current size of the cache.
      Specified by:
      getSize in interface Cache