Interface ICache<K,​V>

  • Type Parameters:
    K - The object type that acts as the key for the cache
    V - The value that is stored in the cache
    All Known Implementing Classes:
    HashMapCache, HazelcastCache, JcsCache

    public interface ICache<K,​V>
    Interface that All cache objects must abide by so components may instantiate any implementation of a cache - no matter what cache it is.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void clear()
      Remove all entries from the cache.
      V get​(K key)
      Retrieve the value associated with the given key.
      Iterable<K> getAllKeys()
      Get all keys present in the cache.
      Iterable<V> getAllValues()
      Get all values present in the cache.
      void put​(K key, V value)
      Add a new key-value pair to the cache.
      default void putSafe​(K key, V value)
      Add a new key-value pair to the cache, but only if there is existing entry associated with the specified key.
      void remove​(K key)
      Remove the entry associated with the specified key.
      default int size()
      Get the size of the cache.
    • Method Detail

      • get

        V get​(K key)
        throws CacheOperationException
        Retrieve the value associated with the given key.
        Parameters:
        key - the key to lookup in the cache
        Returns:
        the value associated with the key
        Throws:
        CacheOperationException - if there is an error getting the key-value pair from the cache
      • put

        void put​(K key,
                 V value)
          throws CacheOperationException
        Add a new key-value pair to the cache.
        Parameters:
        key - the key to add
        value - the value to add
        Throws:
        CacheOperationException - if there is an error adding the new key-value pair to the cache
      • putSafe

        default void putSafe​(K key,
                             V value)
                      throws OverwritingException,
                             CacheOperationException
        Add a new key-value pair to the cache, but only if there is existing entry associated with the specified key.
        Parameters:
        key - the key to add
        value - the value to add
        Throws:
        CacheOperationException - if there is an error adding the new key-value pair to the cache
        OverwritingException - if the specified key already exists in the cache with a non-null value
      • remove

        void remove​(K key)
        Remove the entry associated with the specified key.
        Parameters:
        key - the key of the entry to remove
      • getAllValues

        Iterable<V> getAllValues()
        Get all values present in the cache.
        Returns:
        a Iterable containing all of the cache values
      • getAllKeys

        Iterable<K> getAllKeys()
        Get all keys present in the cache.
        Returns:
        a Iterable containing all of the cache keys
      • size

        default int size()
        Get the size of the cache.
        Returns:
        the number of entries in the caches