Class MemoryCache<K,​V>

java.lang.Object
games.stendhal.client.MemoryCache<K,​V>
Type Parameters:
K - key type
V - value type

public final class MemoryCache<K,​V> extends Object
A Map like cache that uses SoftReferences to store the cached items to allow the garbage collector to reclaim the memory in need. Unlike WeakHashMap, the entries are retained by value rather than by key.
  • Constructor Details

    • MemoryCache

      public MemoryCache()
  • Method Details

    • get

      public V get(K key)
      Get an object from the cache.
      Parameters:
      key - the key corresponding to the object
      Returns:
      cached object, or null if there's no object for the key in the cache
    • put

      public void put(K key, V value)
      Store an object to the cache.
      Parameters:
      key - key for accessing the object
      value - the object to be stored