Class ExternalCache

java.lang.Object
org.silverpeas.kernel.cache.model.AbstractSimpleCache
org.silverpeas.kernel.cache.model.ExternalCache
All Implemented Interfaces:
Cache, SimpleCache

public abstract class ExternalCache extends AbstractSimpleCache implements Cache
A more complete cache provided by an external library. The cache loaded and used by the ApplicationCacheAccessor have to extend this abstract class.
Since:
11/09/13
Author:
Yohann Chastagnier
  • Constructor Details

    • ExternalCache

      public ExternalCache()
  • Method Details

    • add

      public String add(Object value, int timeToLive)
      Description copied from interface: Cache
      Adds a value and generates a unique mapping key from which the value can be retrieved later.
      Specified by:
      add in interface Cache
      Parameters:
      value - an object to add into the cache
      timeToLive - the time to live in seconds of the value in the cache. After this time, the value expires and consequently it is removed from the cache. 0 = unlimited.
      Returns:
      the key to which the added value is mapped in the cache
    • add

      public String add(Object value, int timeToLive, int timeToIdle)
      Description copied from interface: Cache
      Adds a value and generate a unique mapping key to be used to retrieve later the value. When both the time to live and the time to idle are set, the lifetime of the value in the cache is initially bounded by the time to live except if the lifetime computed from the time to live at the last access of the value (access time plus the time to idle) exceeds this initial lifetime.
      Specified by:
      add in interface Cache
      Parameters:
      value - the object to add in the cache.
      timeToLive - the time to live in seconds of the object in the cache. The time to live can be exceeded if the time to idle is set and the value is accessed after the time to live minus the time to idle. 0 = unlimited.
      timeToIdle - the time to idle in seconds of the object in the cache between two accesses. With the time to live set, the time to idle is taken into account only once the time starting at the access time exceed the initial lifetime of the value computed from the time to live. After this time, the value expires and consequently it is remove from the cache. 0 = unlimited.
      Returns:
      the key to which the added object is mapped in the cache
    • put

      public void put(Object key, Object value)
      Description copied from interface: SimpleCache
      Puts a value for a given key. After 12 hours without be used the value is trashed.
      Specified by:
      put in interface SimpleCache
      Parameters:
      key - the key with which the object to put has to be mapped
      value - the object to put in the cache.
    • put

      public void put(Object key, Object value, int timeToLive)
      Description copied from interface: Cache
      Puts a new value for the given key and updates its time to live.
      Specified by:
      put in interface Cache
      Parameters:
      key - the key with which the object to put has to be mapped.
      value - the object to put in the cache.
      timeToLive - the time to live in seconds of the value in the cache. After this time, the value expires and consequently it is removed from the cache. 0 = unlimited.
    • computeIfAbsent

      public <T> T computeIfAbsent(Object key, Class<T> classType, Supplier<T> valueSupplier)
      Description copied from interface: SimpleCache
      Gets a typed element mapped with the specified key from the cache or computes it with the specified value supplier if no such key exists. If an element exists for the given key but the object type doesn't match the expected one, a new computation is performed. If the element returned by the computation is null, then nothing is put into the cache. The value supplier should not modify this cache during computation.
      Specified by:
      computeIfAbsent in interface SimpleCache
      Overrides:
      computeIfAbsent in class AbstractSimpleCache
      Type Parameters:
      T - the concrete type of the object to get.
      Parameters:
      key - the key with which the object to get is mapped in the cache.
      classType - the class of the instance to get.
      valueSupplier - the function that will computes the data to put into the cache.
      Returns:
      the object mapped with the key or null if there is no object to map with the specified key.
    • computeIfAbsent

      public <T> T computeIfAbsent(Object key, Class<T> classType, int timeToLive, Supplier<T> valueSupplier)
      Description copied from interface: Cache
      Gets a typed element from the cache and computes it if it does not yet exist. If an element exists for the given key but the object type doesn't correspond, a new computation is performed.
      Specified by:
      computeIfAbsent in interface Cache
      Type Parameters:
      T - the concrete type of the object to get.
      Parameters:
      key - the key with which the object to get is mapped in the cache.
      classType - the class of the instance to get.
      timeToLive - the time to live in seconds of the object in the cache. The time to live can be exceeded if the time to idle is set and the value is accessed after the time to live minus the time to idle. 0 = unlimited.
      valueSupplier - the function that will computes the data to put into the cache.
      Returns:
      the object mapped with the key or null if no there is no object mapped with the specified key.