Class MemoryCache<K,V>

  • Type Parameters:
    K - the key type.
    V - the value type.


    public class MemoryCache<K,V>
    extends Object
    • Constructor Summary

      Constructors

      Constructor and Description
      MemoryCache(int size)
      Create a memory cache.
    • Constructor Detail

      • MemoryCache

        public MemoryCache(int size)
        Create a memory cache.
        Parameters:
        size - the number of elements to store.
    • Method Detail

      • getSize

        public int getSize()
      • setSize

        public void setSize(int size)
      • put

        public void put(K key,
                        V value)
        Put key, value into the cache.
        Parameters:
        key - the key.
        value - the value.
      • get

        public V get(K key)
        Get the stored element.
        Parameters:
        key - the key to retrieve a value for.
        Returns:
        the value.
      • remove

        public V remove(K key)
        Remove and get the stored element if any.
        Parameters:
        key - the key to remove the value for.
        Returns:
        the removed element or null.
      • clear

        public void clear()
        Clear this cache. Removes all elements.