Package io.lettuce.core.support.caching
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 fromget(Object, Callable)
in case of the value loader callback failing with an exception.
-
Method Summary
All Methods Instance Methods Abstract Methods 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 fromvalueLoader
if necessary.
-
-
-
Method Detail
-
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 alsonull
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 fromvalueLoader
if necessary. This method provides a simple substitute for the conventional "if cached, return; otherwise create, cache and return" pattern. If thevalueLoader
throws an exception, it is wrapped in aCacheFrontend.ValueRetrievalException
- Parameters:
key
- the key whose associated value is to be returnedvalueLoader
- 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 thevalueLoader
throws an exception or returns anull
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-