Class HashMapCache<K,​V>

  • Type Parameters:
    K - The object type that acts as the key for the HashMap
    V - The value that is stored in the HashMap
    All Implemented Interfaces:
    ICache<K,​V>

    public class HashMapCache<K,​V>
    extends Object
    implements ICache<K,​V>
    Simple implementation of the ICache interface, using a HashMap as the cache data store.
    • Constructor Detail

      • HashMapCache

        public HashMapCache​(boolean useJavaSerialisation)
      • HashMapCache

        public HashMapCache()
    • Method Detail

      • get

        public V get​(K key)
        Description copied from interface: ICache
        Retrieve the value associated with the given key.
        Specified by:
        get in interface ICache<K,​V>
        Parameters:
        key - the key to lookup in the cache
        Returns:
        the value associated with the key
      • put

        public void put​(K key,
                        V value)
        Description copied from interface: ICache
        Add a new key-value pair to the cache.
        Specified by:
        put in interface ICache<K,​V>
        Parameters:
        key - the key to add
        value - the value to add
      • remove

        public void remove​(K key)
        Description copied from interface: ICache
        Remove the entry associated with the specified key.
        Specified by:
        remove in interface ICache<K,​V>
        Parameters:
        key - the key of the entry to remove
      • getAllValues

        public Collection<V> getAllValues()
        Description copied from interface: ICache
        Get all values present in the cache.
        Specified by:
        getAllValues in interface ICache<K,​V>
        Returns:
        a Iterable containing all of the cache values
      • getAllKeys

        public Set<K> getAllKeys()
        Description copied from interface: ICache
        Get all keys present in the cache.
        Specified by:
        getAllKeys in interface ICache<K,​V>
        Returns:
        a Iterable containing all of the cache keys
      • size

        public int size()
        Description copied from interface: ICache
        Get the size of the cache.
        Specified by:
        size in interface ICache<K,​V>
        Returns:
        the number of entries in the caches
      • clear

        public void clear()
        Description copied from interface: ICache
        Remove all entries from the cache.
        Specified by:
        clear in interface ICache<K,​V>