Class TimeoutFIFOCache<K,V>

java.lang.Object
com.reve.utils.memory.TimeoutFIFOCache<K,V>

public class TimeoutFIFOCache<K,V> extends Object
This is a Thread Safe, specialized LinkedHashMap. If any element spends more time than the given timeout, It will be automatically remove from the map. This map will also maintain the order of insertion in FIFO mode.
  • Constructor Details

    • TimeoutFIFOCache

      public TimeoutFIFOCache(long timeOut)
      Constructor
      Parameters:
      timeOut - Maximum allowed time in millisecond of an element to be in this map. When the elements become older than the given timeout it will automatically be removed on next call of refreshCache().
  • Method Details

    • get

      public V get(K key)
      Get the value mapped with the given key. If no value present in the cache then a null object will be returned.
      Parameters:
      key - Value will be searched using this key.
      Returns:
      the value mapped with the given key. If no value present in the cache then a null object will be returned.
    • put

      public V put(K key, V 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.
      Parameters:
      key - – key with which the specified value is to be associated
      value - – value to be associated with the specified key
      Returns:
      the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
    • size

      public int size()
      Return the size of this cache.
      Returns:
      the size of this cache.
    • clear

      public void clear()
      Clear the whole cache.
    • refreshCache

      public List<V> refreshCache()
      Remove all the time-out entry. This method should be called periodically from external source.
      Returns:
      the list if values that has been removed from the cache