Class ExpirationCache<K,​V>

  • Type Parameters:
    K - the type of the keys of this cache.
    V - the type of the values this cache caches.
    All Implemented Interfaces:
    java.util.Map<K,​V>, Cache<K,​V>

    public class ExpirationCache<K,​V>
    extends java.lang.Object
    implements Cache<K,​V>, java.util.Map<K,​V>
    A cache which expires its values.
    • Nested Class Summary

      • 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
      ExpirationCache​(int maxSize, long defaultExpirationTime)
      Construct a new expiration cache.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      V get​(java.lang.Object key)  
      int getMaxCacheSize()
      Return the maximum cache Size.
      boolean isEmpty()  
      java.util.Set<K> keySet()  
      V lookup​(K key)
      Returns the value of the specified key, or null.
      V put​(K key, V value)
      Put a value in the cache.
      V put​(K key, V value, long expirationTime)
      Put a value in the cache with the specified expiration time in milliseconds.
      void putAll​(java.util.Map<? extends K,​? extends V> m)  
      V remove​(java.lang.Object key)
      Remove a entry with the given key from the cache.
      void setDefaultExpirationTime​(long defaultExpirationTime)
      Set the default expiration time in milliseconds.
      void setMaxCacheSize​(int maxCacheSize)
      Set the maximum cache size.
      int size()  
      java.util.Collection<V> values()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • ExpirationCache

        public ExpirationCache​(int maxSize,
                               long defaultExpirationTime)
        Construct a new expiration cache.
        Parameters:
        maxSize - the maximum size.
        defaultExpirationTime - the default expiration time in milliseconds.
    • Method Detail

      • setDefaultExpirationTime

        public final void setDefaultExpirationTime​(long defaultExpirationTime)
        Set the default expiration time in milliseconds.
        Parameters:
        defaultExpirationTime - the default expiration time.
      • put

        public V put​(K key,
                     V value)
        Description copied from interface: Cache
        Put a value in the cache.
        Specified by:
        put in interface Cache<K,​V>
        Specified by:
        put in interface java.util.Map<K,​V>
        Parameters:
        key - the key of the value.
        value - the value.
        Returns:
        the previous value or null.
      • put

        public V put​(K key,
                     V value,
                     long expirationTime)
        Put a value in the cache with the specified expiration time in milliseconds.
        Parameters:
        key - the key of the value.
        value - the value.
        expirationTime - the expiration time in milliseconds.
        Returns:
        the previous value or null.
      • lookup

        public V lookup​(K key)
        Description copied from interface: Cache
        Returns the value of the specified key, or null.
        Specified by:
        lookup in interface Cache<K,​V>
        Parameters:
        key - the key.
        Returns:
        the value found in the cache, or null.
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
      • remove

        public V remove​(java.lang.Object key)
        Remove a entry with the given key from the cache.
        Specified by:
        remove in interface java.util.Map<K,​V>
        Parameters:
        key - the key of the value to remove.
        Returns:
        the remove value, or null.
      • getMaxCacheSize

        public int getMaxCacheSize()
        Description copied from interface: Cache
        Return the maximum cache Size.
        Specified by:
        getMaxCacheSize in interface Cache<K,​V>
        Returns:
        the maximum cache size.
      • setMaxCacheSize

        public void setMaxCacheSize​(int maxCacheSize)
        Description copied from interface: Cache
        Set the maximum cache size.
        Specified by:
        setMaxCacheSize in interface Cache<K,​V>
        Parameters:
        maxCacheSize - the new maximum cache size.
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
      • values

        public java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>