Class ConcurrentCache<T>

  • All Implemented Interfaces:
    java.io.Serializable, java.util.concurrent.ConcurrentMap<java.lang.Object,​T>, java.util.Map<java.lang.Object,​T>, Cache<T>

    public class ConcurrentCache<T>
    extends java.util.concurrent.ConcurrentHashMap<java.lang.Object,​T>
    implements Cache<T>
    The ConcurrentCache interface is used to represent a cache that will store key value pairs. This implementation is backed by a ConcurrentHashMap for best performance.
    Author:
    Niall Gallagher
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap

        java.util.concurrent.ConcurrentHashMap.KeySetView<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      ConcurrentCache()
      Constructor for the ConcurrentCache object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cache​(java.lang.Object key, T value)
      This method is used to insert a key value mapping in to the cache.
      boolean contains​(java.lang.Object key)
      This is used to determine whether the specified key exists with in the cache.
      T fetch​(java.lang.Object key)
      This method is used to get the value from the cache that is mapped to the specified key.
      T take​(java.lang.Object key)
      This is used to exclusively take the value mapped to the specified key from the cache.
      • Methods inherited from class java.util.concurrent.ConcurrentHashMap

        clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, get, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, put, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, values
      • Methods inherited from class java.util.AbstractMap

        clone
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.simpleframework.xml.util.Cache

        isEmpty
    • Constructor Detail

      • ConcurrentCache

        public ConcurrentCache()
        Constructor for the ConcurrentCache object. This is an implementation of a cache that uses the conventional concurrent hash map from the Java collections API.
    • Method Detail

      • cache

        public void cache​(java.lang.Object key,
                          T value)
        This method is used to insert a key value mapping in to the cache. The value can later be retrieved or removed from the cache if desired. If the value associated with the key is null then nothing is stored within the cache.
        Specified by:
        cache in interface Cache<T>
        Parameters:
        key - this is the key to cache the provided value to
        value - this is the value that is to be cached
      • take

        public T take​(java.lang.Object key)
        This is used to exclusively take the value mapped to the specified key from the cache. Invoking this is effectively removing the value from the cache.
        Specified by:
        take in interface Cache<T>
        Parameters:
        key - this is the key to acquire the cache value with
        Returns:
        this returns the value mapped to the specified key
      • fetch

        public T fetch​(java.lang.Object key)
        This method is used to get the value from the cache that is mapped to the specified key. If there is no value mapped to the specified key then this method will return a null.
        Specified by:
        fetch in interface Cache<T>
        Parameters:
        key - this is the key to acquire the cache value with
        Returns:
        this returns the value mapped to the specified key
      • contains

        public boolean contains​(java.lang.Object key)
        This is used to determine whether the specified key exists with in the cache. Typically this can be done using the fetch method, which will acquire the object.
        Specified by:
        contains in interface Cache<T>
        Overrides:
        contains in class java.util.concurrent.ConcurrentHashMap<java.lang.Object,​T>
        Parameters:
        key - this is the key to check within this segment
        Returns:
        true if the specified key is within the cache