- 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 classCacheFrontend.ValueRetrievalExceptionWrapper exception to be thrown fromget(Object, Callable)in case of the value loader callback failing with an exception. -
Method Summary
Modifier and Type Method Description voidclose()Closes this cache frontend and releases any system resources associated with it.Vget(K key)Return the value to which this cache maps the specified key.Vget(K key, Callable<V> valueLoader)Return the value to which this cache maps the specified key, obtaining that value fromvalueLoaderif necessary.
-
Method Details
-
get
Return the value to which this cache maps the specified key.Note: This method does not allow for differentiating between a cached
nullvalue 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
nullitself), or alsonullif the cache contains no mapping for this key. - See Also:
CacheAccessor.get(Object),RedisCache.get(Object)
-
get
Return the value to which this cache maps the specified key, obtaining that value fromvalueLoaderif necessary. This method provides a simple substitute for the conventional "if cached, return; otherwise create, cache and return" pattern. If thevalueLoaderthrows 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 thevalueLoaderthrows an exception or returns anullvalue.
-
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-