K - Key type.V - Value type.public class ClientSideCaching<K,V> extends Object implements CacheFrontend<K,V>
CacheFrontend that represents a two-level
cache backed by a client-side and a Redis cache.
For example:
MapclientCache = new ConcurrentHashMap<>(); StatefulRedisConnection<String, String> connection = redisClient.connect(); CacheFrontend<String, String> frontend = ClientSideCaching.enable(CacheAccessor.forMap(clientCache), connection, TrackingArgs.Builder.enabled()); String value = frontend.get(key);
CacheFrontend.ValueRetrievalException| Modifier and Type | Method and Description |
|---|---|
void |
addInvalidationListener(Consumer<K> invalidationListener) |
void |
close()
Closes this cache frontend and releases any system resources associated with it.
|
static <K,V> CacheFrontend<K,V> |
create(CacheAccessor<K,V> cacheAccessor,
StatefulRedisConnection<K,V> connection)
Create a server-assisted Client side caching for the given
CacheAccessor and StatefulRedisConnection. |
static <K,V> CacheFrontend<K,V> |
enable(CacheAccessor<K,V> cacheAccessor,
StatefulRedisConnection<K,V> connection,
TrackingArgs tracking)
Enable server-assisted Client side caching for the given
CacheAccessor and StatefulRedisConnection. |
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. |
public static <K,V> CacheFrontend<K,V> enable(CacheAccessor<K,V> cacheAccessor, StatefulRedisConnection<K,V> connection, TrackingArgs tracking)
CacheAccessor and StatefulRedisConnection.
Note that the CacheFrontend is associated with a Redis connection. Make sure to close the frontend object to release the Redis connection after use.
K - Key type.V - Value type.cacheAccessor - the accessor used to interact with the client-side cache.connection - the Redis connection to use. The connection will be associated with CacheFrontend and must be
closed through CacheFrontend.close().tracking - the tracking parameters.CacheFrontend for value retrieval.public static <K,V> CacheFrontend<K,V> create(CacheAccessor<K,V> cacheAccessor, StatefulRedisConnection<K,V> connection)
CacheAccessor and StatefulRedisConnection.
This method expects that client key tracking is already configured.
Note that the CacheFrontend is associated with a Redis connection. Make sure to close the frontend object to release the Redis connection after use.
K - Key type.V - Value type.cacheAccessor - the accessor used to interact with the client-side cache.connection - the Redis connection to use. The connection will be associated with CacheFrontend and must be
closed through CacheFrontend.close().CacheFrontend for value retrieval.public void close()
CacheFrontendclose in interface CacheFrontend<K,V>close in interface Closeableclose in interface AutoCloseablepublic V get(K key)
CacheFrontend
Note: This method does not allow for differentiating between a cached null value and no cache entry found at all.
get in interface CacheFrontend<K,V>key - the key whose associated value is to be returned.null itself), or also null if
the cache contains no mapping for this key.CacheAccessor.get(Object),
RedisCache.get(Object)public V get(K key, Callable<V> valueLoader)
CacheFrontendvalueLoader 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.ValueRetrievalExceptionget in interface CacheFrontend<K,V>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.Copyright © 2022 lettuce.io. All rights reserved.