Class SmartCacheImpl<K,​V>

  • All Implemented Interfaces:
    SmartCache<K,​V>
    Direct Known Subclasses:
    HardSmartCache, SoftSmartCache

    public abstract class SmartCacheImpl<K,​V>
    extends java.lang.Object
    implements SmartCache<K,​V>
    A base implementation of the SmartCache interface which enforces synchronization with a ReadWrite lock.
    • Constructor Summary

      Constructors 
      Constructor Description
      SmartCacheImpl()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the contents of this cache.
      protected abstract void clearImpl()  
      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.
      protected abstract V getImpl​(K key)  
      protected abstract java.util.Iterator<java.util.Map.Entry<K,​V>> iteratorImpl()
      Must provide an iterator on the contents of the cache.
      V put​(K key, V value)
      Places a key/value pair into the cache.
      protected abstract V putImpl​(K key, V value)  
      V remove​(K key)
      Removes a key from the cache.
      protected abstract V removeImpl​(K key)  
      int size()
      Returns the number of elements in cache.
      protected abstract int sizeImpl()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SmartCacheImpl

        public SmartCacheImpl()
    • Method Detail

      • iteratorImpl

        protected abstract java.util.Iterator<java.util.Map.Entry<K,​V>> iteratorImpl()
        Must provide an iterator on the contents of the cache. It does not need to be thread safe because we will handle that in SmartCacheImpl.
      • putImpl

        protected abstract V putImpl​(K key,
                                     V value)
      • getImpl

        protected abstract V getImpl​(K key)
      • removeImpl

        protected abstract V removeImpl​(K key)
      • clearImpl

        protected abstract void clearImpl()
      • sizeImpl

        protected abstract int sizeImpl()
      • put

        public V put​(K key,
                     V value)
        Description copied from interface: SmartCache
        Places a key/value pair into the cache.
        Specified by:
        put in interface SmartCache<K,​V>
        Parameters:
        key - Key
        value - Value
        Returns:
        the previous value of key or null
      • get

        public V get​(K key)
        Description copied from interface: SmartCache
        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.
        Specified by:
        get in interface SmartCache<K,​V>
      • remove

        public V remove​(K key)
        Description copied from interface: SmartCache
        Removes a key from the cache.
        Specified by:
        remove in interface SmartCache<K,​V>
        Parameters:
        key - Key
        Returns:
        Previous value associated with the key
      • clear

        public void clear()
        Description copied from interface: SmartCache
        Clears the contents of this cache.
        Specified by:
        clear in interface SmartCache<K,​V>
      • size

        public int size()
        Description copied from interface: SmartCache
        Returns the number of elements in cache.
        Specified by:
        size in interface SmartCache<K,​V>
      • execute

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