Interface Cache

  • All Superinterfaces:
    Serializable
    All Known Implementing Classes:
    DefaultCache, TimeToLiveCache

    public interface Cache
    extends Serializable
    Interface that abstracts a simple get and put operation for a concrete cache implementation.

    Note that this takes Strings for both key and value since it's not intended as a general cache solution, but is something specific for the Cache component which caches rendered output.

    Since:
    1.1
    Author:
    Arjan Tijms
    • Method Detail

      • get

        String get​(String key)
        Gets a value from the 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

        Serializable getObject​(String key)
        Gets a value from the 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

        void put​(String key,
                 String value)
        Stores a value in the cache
        Parameters:
        key - the key under which a value is to be stored
        value - the value that is to be stored
      • putObject

        void putObject​(String key,
                       Serializable value,
                       int timeToLive)
        Stores a value in the 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 get(String) should return null.
      • put

        void put​(String key,
                 String value,
                 int timeToLive)
        Stores a value in the 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 get(String) should return null.
      • getAttribute

        Serializable getAttribute​(String key,
                                  String name)
        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.

        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.
        Since:
        1.2
      • putAttribute

        void putAttribute​(String key,
                          String name,
                          Serializable value,
                          int timeToLive)
        Stores a named attribute in the cache entry identified by the key parameter.
        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.
        Since:
        1.2
      • remove

        void remove​(String key)
        Removes a value from the cache
        Parameters:
        key - the key under which a value is to be stored
      • clear

        void clear()
        Clears the entire cache
        Since:
        3.3