Class TimeToLiveCache

java.lang.Object
org.omnifaces.util.cache.TimeToLiveCache
All Implemented Interfaces:
Serializable, Cache
Direct Known Subclasses:
DefaultCache

public abstract class TimeToLiveCache extends Object implements Cache
Base class that can be used by Map based caches that don't support time to live semantics and arbitrary attributes natively.
Since:
1.1
Author:
Arjan Tijms
See Also:
  • Constructor Details

    • TimeToLiveCache

      protected TimeToLiveCache(Integer defaultTimeToLive)
  • Method Details

    • get

      public String get(String key)
      Description copied from interface: Cache
      Gets a value from the cache
      Specified by:
      get in interface Cache
      Parameters:
      key - the key under which a value was previously stored
      Returns:
      The previously stored value, or null if no such value exists
    • getObject

      public Serializable getObject(String key)
      Description copied from interface: Cache
      Gets a value from the cache
      Specified by:
      getObject in interface Cache
      Parameters:
      key - the key under which a value was previously stored
      Returns:
      The previously stored value, or null if no such value exists
    • put

      public void put(String key, String value)
      Description copied from interface: Cache
      Stores a value in the cache
      Specified by:
      put in interface Cache
      Parameters:
      key - the key under which a value is to be stored
      value - the value that is to be stored
    • put

      public void put(String key, String value, int timeToLive)
      Description copied from interface: Cache
      Stores a value in the cache
      Specified by:
      put in interface Cache
      Parameters:
      key - the key under which a value is to be stored
      value - the value that is to be stored
      timeToLive - the amount of time in seconds for which the cached value is valid from the time it's being added to the cache. It's provider specific whether the cache implementation will actually remove (evict) the entry after this time has elapsed or will only perform a check upon accessing the cache entry. Whatever method the implementation chooses; after this time is elapsed a call to Cache.get(String) should return null.
    • putObject

      public void putObject(String key, Serializable value, int timeToLive)
      Description copied from interface: Cache
      Stores a value in the cache
      Specified by:
      putObject in interface Cache
      Parameters:
      key - the key under which a value is to be stored
      value - the value that is to be stored
      timeToLive - the amount of time in seconds for which the cached value is valid from the time it's being added to the cache. It's provider specific whether the cache implementation will actually remove (evict) the entry after this time has elapsed or will only perform a check upon accessing the cache entry. Whatever method the implementation chooses; after this time is elapsed a call to Cache.get(String) should return null.
    • putAttribute

      public void putAttribute(String key, String name, Serializable value, int timeToLive)
      Description copied from interface: Cache
      Stores a named attribute in the cache entry identified by the key parameter.
      Specified by:
      putAttribute in interface Cache
      Parameters:
      key - key that identifies the first level cache entry
      name - name of the attribute in the second level
      value - value associated with the {key, name} hierarchy.
      timeToLive - the amount of time in seconds for which the cached value is valid. Only used when there's no first level entry yet.
    • getAttribute

      public Serializable getAttribute(String key, String name)
      Description copied from interface: Cache
      Gets a named attribute from the cache entry identified by the key parameter.

      This in effect implements a 2-level multi-map, which the single main value stored in the first level, and the optional attributes stored in the second level.

      Specified by:
      getAttribute in interface Cache
      Parameters:
      key - key that identifies the first level cache entry
      name - name of the attribute in the second level
      Returns:
      the value associated with the {key, name} hierarchy.
    • remove

      public void remove(String key)
      Description copied from interface: Cache
      Removes a value from the cache
      Specified by:
      remove in interface Cache
      Parameters:
      key - the key under which a value is to be stored
    • clear

      public void clear()
      Description copied from interface: Cache
      Clears the entire cache
      Specified by:
      clear in interface Cache
    • setCacheStore

      protected void setCacheStore(Map<String,CacheEntry> cacheStore)