Class DefaultCache<KeyType,​ValueType>

  • Type Parameters:
    KeyType - type of key being stored
    ValueType - java of value being stored
    All Implemented Interfaces:
    Cache<KeyType,​ValueType>

    public class DefaultCache<KeyType,​ValueType>
    extends Object
    implements Cache<KeyType,​ValueType>
    Default cache manager implementation backed by DefaultCache.LRUMap
    • Constructor Detail

      • DefaultCache

        public DefaultCache​(String name,
                            int maximumSize)
        Default cache manager implementation backed by DefaultCache.LRUMap
        Parameters:
        name - unique cache name
        maximumSize - maximum cache size
    • Method Detail

      • clear

        public void clear()
        Removes all of the mappings from this map. The map will be empty after this call returns.
        Specified by:
        clear in interface Cache<KeyType,​ValueType>
      • put

        public void put​(KeyType key,
                        ValueType value)
        Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
        Specified by:
        put in interface Cache<KeyType,​ValueType>
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
      • get

        public ValueType get​(KeyType key)
        Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
        Specified by:
        get in interface Cache<KeyType,​ValueType>
        Parameters:
        key - key with which the specified value is to be associated
        Returns:
        value to be associated with the specified key
      • getName

        public String getName()
        Returns the name of the overall cache store
        Specified by:
        getName in interface Cache<KeyType,​ValueType>
        Returns:
        name of the overall cache store
      • getSize

        public long getSize()
        Returns the number of key-value mappings in this map.
        Specified by:
        getSize in interface Cache<KeyType,​ValueType>
        Returns:
        the number of key-value mappings in this map
      • getMaxSize

        public int getMaxSize()
        Returns the maximum number of entries which the cache can hold
        Specified by:
        getMaxSize in interface Cache<KeyType,​ValueType>
        Returns:
        maximum number of entries which the cache can hold
      • containsKey

        public boolean containsKey​(KeyType key)
        Returns true if this map contains a mapping for the specified key.
        Specified by:
        containsKey in interface Cache<KeyType,​ValueType>
        Parameters:
        key - The key whose presence in this map is to be tested
        Returns:
        true if this map contains a mapping for the specified key.