Interface Cache

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      String add​(Object value, int timeToLive)
      Adds a value and generates a unique mapping key to be used to retrieve later the value.
      String add​(Object value, int timeToLive, int timeToIdle)
      Adds a value and generate a unique mapping key to be used to retrieve later the value.
      <T> T computeIfAbsent​(Object key, Class<T> classType, int timeToLive, int timeToIdle, Supplier<T> valueSupplier)
      Gets a typed element from the cache and computes it if it does not yet exist.
      <T> T computeIfAbsent​(Object key, Class<T> classType, int timeToLive, Supplier<T> valueSupplier)
      Gets a typed element from the cache and computes it if it does not yet exist.
      void put​(Object key, Object value, int timeToLive)
      Puts a new value for the given key and updates its time to live.
      void put​(Object key, Object value, int timeToLive, int timeToIdle)
      Puts a new value for the given key and updates both its time to live and its time to idle.
    • Method Detail

      • add

        String add​(Object value,
                   int timeToLive)
        Adds a value and generates a unique mapping key to be used to retrieve later the value.
        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

        String add​(Object value,
                   int timeToLive,
                   int timeToIdle)
        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.
        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

        void put​(Object key,
                 Object value,
                 int timeToLive)
        Puts a new value for the given key and updates its time to live.
        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.
      • put

        void put​(Object key,
                 Object value,
                 int timeToLive,
                 int timeToIdle)
        Puts a new value for the given key and updates both its time to live and its time to idle. 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.
        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 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.
      • computeIfAbsent

        <T> T computeIfAbsent​(Object key,
                              Class<T> classType,
                              int timeToLive,
                              Supplier<T> valueSupplier)
        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.
        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.
        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.
        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 no there is no object mapped with the specified key.
      • computeIfAbsent

        <T> T computeIfAbsent​(Object key,
                              Class<T> classType,
                              int timeToLive,
                              int timeToIdle,
                              Supplier<T> valueSupplier)
        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.
        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.
        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.
        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 no there is no object mapped with the specified key.