@EachBean(value=RedisCacheConfiguration.class) public class RedisCache extends Object implements SyncCache<io.lettuce.core.api.StatefulConnection<?,?>>
SyncCache
for Lettuce / Redis.Modifier and Type | Class and Description |
---|---|
protected class |
RedisCache.RedisAsyncCache
Redis Async cache implementation.
|
Constructor and Description |
---|
RedisCache(RedisCacheConfiguration redisCacheConfiguration,
ConversionService<?> conversionService,
BeanLocator beanLocator)
Creates a new redis cache for the given arguments.
|
Modifier and Type | Method and Description |
---|---|
AsyncCache<io.lettuce.core.api.StatefulConnection<?,?>> |
async()
This method should return an async API version of this cache interface implementation.
|
protected AsyncCacheCommands |
asyncCommands(io.lettuce.core.api.StatefulConnection<String,String> connection)
Get the asynchronous commands for the stateful connection.
|
<T> Optional<T> |
get(Object key,
Argument<T> requiredType)
Resolve the given value for the given key.
|
<T> T |
get(Object key,
Argument<T> requiredType,
Supplier<T> supplier)
Resolve the given value for the given key.
|
protected String |
getKeysPattern() |
String |
getName() |
io.lettuce.core.api.StatefulConnection<?,?> |
getNativeCache() |
protected <T> Optional<T> |
getValue(Argument<T> requiredType,
SyncCacheCommands commands,
byte[] serializedKey)
Get the value based on the parameters.
|
void |
invalidate(Object key)
Invalidate the value for the given key.
|
void |
invalidateAll()
Invalidate all cached values within this cache.
|
void |
put(Object key,
Object value)
Cache the specified value using the specified key.
|
<T> Optional<T> |
putIfAbsent(Object key,
T value)
Cache the specified value using the specified key if it is not already present.
|
protected <T> void |
putValue(SyncCacheCommands commands,
byte[] serializedKey,
T value)
Place the value in the cache.
|
protected byte[] |
serializeKey(Object key)
Serialize the key.
|
protected SyncCacheCommands |
syncCommands(io.lettuce.core.api.StatefulConnection<String,String> connection)
Get the synchronous commands for the stateful connection.
|
public RedisCache(RedisCacheConfiguration redisCacheConfiguration, ConversionService<?> conversionService, BeanLocator beanLocator)
redisCacheConfiguration
- The configurationconversionService
- The conversion servicebeanLocator
- The bean locator used to discover the redis connection from the configurationpublic String getName()
public io.lettuce.core.api.StatefulConnection<?,?> getNativeCache()
getNativeCache
in interface Cache<io.lettuce.core.api.StatefulConnection<?,?>>
public <T> Optional<T> get(Object key, Argument<T> requiredType)
SyncCache
public <T> T get(Object key, Argument<T> requiredType, Supplier<T> supplier)
SyncCache
Supplier
will
be invoked and the return value cached.get
in interface SyncCache<io.lettuce.core.api.StatefulConnection<?,?>>
T
- The concrete typekey
- The cache keyrequiredType
- The required typesupplier
- The supplier that should be invoked if the value is not foundpublic <T> Optional<T> putIfAbsent(Object key, T value)
SyncCache
Cache the specified value using the specified key if it is not already present.
putIfAbsent
in interface SyncCache<io.lettuce.core.api.StatefulConnection<?,?>>
T
- The concrete typekey
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyOptional.empty()
if the specified value parameter was cachedpublic void put(Object key, Object value)
SyncCache
Cache the specified value using the specified key.
public void invalidate(Object key)
SyncCache
invalidate
in interface SyncCache<io.lettuce.core.api.StatefulConnection<?,?>>
key
- The key to invalidpublic void invalidateAll()
SyncCache
invalidateAll
in interface SyncCache<io.lettuce.core.api.StatefulConnection<?,?>>
public AsyncCache<io.lettuce.core.api.StatefulConnection<?,?>> async()
SyncCache
This method should return an async API version of this cache interface implementation.
The default behaviour assumes the cache implementation is running in-memory and performs no blocking
operations and hence simply delegates to the SyncCache
implementation.
If I/O operations are required implementors should override this API and provide an API that implements
AsyncCache
in a non-blocking manner.
async
in interface SyncCache<io.lettuce.core.api.StatefulConnection<?,?>>
AsyncCache
implementation for this cacheprotected <T> Optional<T> getValue(Argument<T> requiredType, SyncCacheCommands commands, byte[] serializedKey)
T
- type of the argumentrequiredType
- requiredTypecommands
- commandsserializedKey
- serializedKeyprotected String getKeysPattern()
protected <T> void putValue(SyncCacheCommands commands, byte[] serializedKey, T value)
T
- type of the valuecommands
- commandsserializedKey
- serializedKeyvalue
- valueprotected byte[] serializeKey(Object key)
key
- The keyprotected SyncCacheCommands syncCommands(io.lettuce.core.api.StatefulConnection<String,String> connection)
connection
- stateful connectionprotected AsyncCacheCommands asyncCommands(io.lettuce.core.api.StatefulConnection<String,String> connection)
connection
- stateful connection