Module lettuce.core

Interface CacheFrontend<K,​V>

Type Parameters:
K - Key type.
V - Value type.
All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
ClientSideCaching

public interface CacheFrontend<K,​V>
extends Closeable
Interface defining a cache frontend for common cache retrieval operations that using Redis server-side caching assistance.
Since:
6.0
Author:
Mark Paluch
  • Nested Class Summary

    Nested Classes
    Modifier and Type Interface Description
    static class  CacheFrontend.ValueRetrievalException
    Wrapper exception to be thrown from get(Object, Callable) in case of the value loader callback failing with an exception.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes this cache frontend and releases any system resources associated with it.
    V get​(K key)
    Return the value to which this cache maps the specified key.
    V get​(K key, Callable<V> valueLoader)
    Return the value to which this cache maps the specified key, obtaining that value from valueLoader if necessary.
  • Method Details

    • get

      V get​(K key)
      Return the value to which this cache maps the specified key.

      Note: This method does not allow for differentiating between a cached null value and no cache entry found at all.

      Parameters:
      key - the key whose associated value is to be returned.
      Returns:
      the value to which this cache maps the specified key (which may be null itself), or also null if the cache contains no mapping for this key.
      See Also:
      CacheAccessor.get(Object), RedisCache.get(Object)
    • get

      V get​(K key, Callable<V> valueLoader)
      Return the value to which this cache maps the specified key, obtaining that value from valueLoader if necessary. This method provides a simple substitute for the conventional "if cached, return; otherwise create, cache and return" pattern. If the valueLoader throws an exception, it is wrapped in a CacheFrontend.ValueRetrievalException
      Parameters:
      key - the key whose associated value is to be returned
      valueLoader - the value loader that is used to obtain the value if the client-side cache and Redis cache are not associated with a value.
      Returns:
      the value to which this cache maps the specified key.
      Throws:
      CacheFrontend.ValueRetrievalException - if the valueLoader throws an exception or returns a null value.
    • close

      void close()
      Closes this cache frontend and releases any system resources associated with it. If the frontend is already closed then invoking this method has no effect.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable