Interface SmartCache<K,​V>

  • All Known Implementing Classes:
    HardSmartCache, SmartCacheImpl, SoftSmartCache

    public interface SmartCache<K,​V>
    Defines a cache API. Implementations exist for hard and soft references.

    To iterate over the contents of a cache, you must pass a execute(SmartCacheTask) instance. The code using the iterator can be assured that it will be thread safe.

    Implementations are responsible of enforcing thread safety.

    Since:
    Nov 21, 2005
    Author:
    av
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  SmartCache.SmartCacheTask<K,​V>
      Defines a task to be run over the entries of the cache.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()
      Clears the contents of this cache.
      void execute​(SmartCache.SmartCacheTask<K,​V> task)
      Executes a task over the contents of the cache and guarantees exclusive write access while processing.
      V get​(K key)
      Looks up and returns a cache value according to a given key.
      V put​(K key, V value)
      Places a key/value pair into the cache.
      V remove​(K key)
      Removes a key from the cache.
      int size()
      Returns the number of elements in cache.
    • Method Detail

      • put

        V put​(K key,
              V value)
        Places a key/value pair into the cache.
        Parameters:
        key - Key
        value - Value
        Returns:
        the previous value of key or null
      • get

        V get​(K key)
        Looks up and returns a cache value according to a given key. If the cache does not correspond an entry corresponding to the key, null is returned.
      • remove

        V remove​(K key)
        Removes a key from the cache.
        Parameters:
        key - Key
        Returns:
        Previous value associated with the key
      • clear

        void clear()
        Clears the contents of this cache.
      • size

        int size()
        Returns the number of elements in cache.
      • execute

        void execute​(SmartCache.SmartCacheTask<K,​V> task)
        Executes a task over the contents of the cache and guarantees exclusive write access while processing.
        Parameters:
        task - The task to execute.