Interface Cache<K,​V>

  • Type Parameters:
    K - type for the key
    V - type for the value
    All Known Implementing Classes:
    DefaultCache

    public interface Cache<K,​V>
    Cache is a simple Map-like API for caching in-memory on the local platform in a way roughly equivalent to using soft references. Because of the quirks of some platforms, it is better to use this Cache API instead of a WeakHashMap or a Map with weak or soft references.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      V get​(K key)
      Get the value for the specified key, or null when there is no such key.
      void put​(K key, V value)
      Stores a key-value pair in the cache.
      boolean remove​(K key)
      Remove the entry associated with this key.
      void removeAll()
      Remove all entries from the cache
    • Method Detail

      • get

        V get​(K key)
        Get the value for the specified key, or null when there is no such key. The latter can be because there never was an entry with this key stored, or the entry with this key has been reclaimed.
        Parameters:
        key - the key for which we need the value
        Returns:
        the value for the specified key, null in case there is no value corresponding to this key.
      • put

        void put​(K key,
                 V value)
        Stores a key-value pair in the cache. A NullPointerException will be thrown if the key or the value are null.
        Parameters:
        key - the key, should not be null
        value - the value, should not be null
      • remove

        boolean remove​(K key)
        Remove the entry associated with this key.
        Parameters:
        key - the key for which the entry is requested
        Returns:
        true if the cache contained an entry with this key
      • removeAll

        void removeAll()
        Remove all entries from the cache