Class ExpiringValueCache<T>

  • All Implemented Interfaces:
    java.io.Serializable

    public class ExpiringValueCache<T>
    extends java.lang.Object
    implements java.io.Serializable
    Simple cache of a single Object value.

    The object placed in the cache will automatically be discarded after a timeout value.

    Author:
    Kevin Roast
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the cache value
      T get()
      Get the cached object.
      void put​(T value)
      Put a value into the cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExpiringValueCache

        public ExpiringValueCache()
        Default constructor. Uses the default timeout of 1 minute.
      • ExpiringValueCache

        public ExpiringValueCache​(long timeout)
        Constructor
        Parameters:
        timeout - Timeout in milliseconds before cached value is discarded
    • Method Detail

      • put

        public void put​(T value)
        Put a value into the cache. The item will be return from the associated get() method until the timeout expires then null will be returned.
        Parameters:
        value - The object to store in the cache
      • get

        public T get()
        Get the cached object. The set item will be returned until it expires, then null will be returned.
        Returns:
        cached object or null if not set or expired.
      • clear

        public void clear()
        Clear the cache value