Class ExpirationCache<K,V>

java.lang.Object
org.jxmpp.util.cache.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:
Map<K,V>, Cache<K,V>

public class ExpirationCache<K,V> extends Object implements Cache<K,V>, Map<K,V>
A cache which expires its values.
  • Constructor Details

    • 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 Details

    • 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 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(Object key)
      Specified by:
      get in interface Map<K,V>
    • remove

      public V remove(Object key)
      Remove a entry with the given key from the cache.
      Specified by:
      remove in interface 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 Map<K,V>
    • isEmpty

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

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

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

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

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

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

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

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