Class LRUCache<K,V>

java.lang.Object
org.glassfish.hk2.utilities.cache.LRUCache<K,V>
Type Parameters:
K - The key type for this cache
V - The value type for this cache
Direct Known Subclasses:
LRUCacheCheapRead

public abstract class LRUCache<K,V> extends Object
A cache that contains a certain number of entries, and whose oldest accessed entries are removed when removal is necessary.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <K, V> LRUCache<K,V>
    createCache(int maxCacheSize)
    Creates a cache with the given maximum cache size
    abstract V
    get(K key)
    Returns the value associated with the given key.
    abstract int
    Returns the maximum number of entries that will be stored in this cache
    abstract CacheEntry
    put(K key, V value)
    Adds the given key and value pair into the cache
    abstract void
    Clears all entries in the cache, for use when a known event makes the cache incorrect
    abstract void
    This method will remove all cache entries for which this filter matches

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LRUCache

      public LRUCache()
  • Method Details

    • createCache

      public static <K, V> LRUCache<K,V> createCache(int maxCacheSize)
      Creates a cache with the given maximum cache size
      Parameters:
      maxCacheSize - The maximum number of entries in the cache, must be greater than 2
      Returns:
      An LRUCache that can be used to quickly retrieve objects
    • get

      public abstract V get(K key)
      Returns the value associated with the given key. If there is no value, returns null
      Parameters:
      key - Must be a non-null key, appropriate for use as the key to a hash map
      Returns:
      The value associated with the key, or null if there is no such value
    • put

      public abstract CacheEntry put(K key, V value)
      Adds the given key and value pair into the cache
      Parameters:
      key - Must be a non-null key, appropriate for use as the key to a hash map
      value - Must be a non-null value
      Returns:
      A cache entry that can be used to remove this entry from the cache. Will not return null
    • releaseCache

      public abstract void releaseCache()
      Clears all entries in the cache, for use when a known event makes the cache incorrect
    • getMaxCacheSize

      public abstract int getMaxCacheSize()
      Returns the maximum number of entries that will be stored in this cache
      Returns:
      The maximum number of entries that will be stored in this cache
    • releaseMatching

      public abstract void releaseMatching(CacheKeyFilter<K> filter)
      This method will remove all cache entries for which this filter matches
      Parameters:
      filter - Entries in the cache that match this filter will be removed from the cache. If filter is null nothing will be removed from the cache