Interface SimpleCache<K extends java.io.Serializable,​V>

  • All Known Subinterfaces:
    LockingCache<K,​V>
    All Known Implementing Classes:
    MemoryCache

    @AlfrescoPublicApi
    public interface SimpleCache<K extends java.io.Serializable,​V>
    Basic caching interface.

    All implementations must be thread-safe. Additionally, the use of the Serializable for both keys and values ensures that the underlying cache implementations can support both clustered caches as well as persistent caches.

    All implementations must support null values. It therefore follows that

        (simpleCache.contains(key) == true) does not imply (simpleCache.get(key) != null)
     
    but
        (simpleCache.contains(key) == false) implies (simpleCache.get(key) == null)
     
    Author:
    Derek Hulley
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()  
      boolean contains​(K key)  
      V get​(K key)  
      java.util.Collection<K> getKeys()  
      void put​(K key, V value)
      Set the value to store for a given key.
      void remove​(K key)
      Removes the cache entry whether or not the value stored against it is null.
    • Method Detail

      • contains

        boolean contains​(K key)
        Parameters:
        key - the cache key to check up on
        Returns:
        Returns true if there is a cache entry, regardless of whether the value itself is null
      • getKeys

        java.util.Collection<K> getKeys()
      • get

        V get​(K key)
        Parameters:
        key - K
        Returns:
        Returns the value associated with the key. It will be null if the value is null or if the cache doesn't have an entry.
      • put

        void put​(K key,
                 V value)
        Set the value to store for a given key.

        Be sure to use remove if cache entries need to be removed as the cache implementations must treat a null value as a first class object in exactly the same way as a Map will allow storage and retrieval of null values.

        Parameters:
        key - the key against which to store the value
        value - the value to store. null is allowed.
      • remove

        void remove​(K key)
        Removes the cache entry whether or not the value stored against it is null.
        Parameters:
        key - the key value to remove
      • clear

        void clear()