Class AbstractRedisCache<C>
- java.lang.Object
-
- io.micronaut.configuration.lettuce.cache.AbstractRedisCache<C>
-
- Type Parameters:
C- – The native cache implementation
- All Implemented Interfaces:
io.micronaut.cache.Cache<C>,io.micronaut.cache.SyncCache<C>,java.lang.AutoCloseable
- Direct Known Subclasses:
RedisCache,RedisConnectionPoolCache
public abstract class AbstractRedisCache<C> extends java.lang.Object implements io.micronaut.cache.SyncCache<C>, java.lang.AutoCloseableAn abstract class implementing SyncCache for the redis.- Since:
- 5.3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.LongexpireAfterAccessprotected ExpirationAfterWritePolicyexpireAfterWritePolicystatic java.lang.StringINVALID_REDIS_CONNECTION_MESSAGEprotected io.micronaut.core.serialize.ObjectSerializerkeySerializerprotected RedisCacheConfigurationredisCacheConfigurationprotected io.micronaut.core.serialize.ObjectSerializervalueSerializer
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRedisCache(DefaultRedisCacheConfiguration defaultRedisCacheConfiguration, RedisCacheConfiguration redisCacheConfiguration, io.micronaut.core.convert.ConversionService<?> conversionService, io.micronaut.context.BeanLocator beanLocator)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected <T> Tget(byte[] key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier, io.lettuce.core.api.sync.RedisStringCommands<byte[],byte[]> commands)<T> java.util.Optional<T>get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)protected java.lang.StringgetKeysPattern()protected io.lettuce.core.api.async.RedisKeyAsyncCommands<byte[],byte[]>getRedisKeyAsyncCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)protected io.lettuce.core.api.sync.RedisKeyCommands<byte[],byte[]>getRedisKeyCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)protected io.lettuce.core.api.async.RedisStringAsyncCommands<byte[],byte[]>getRedisStringAsyncCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)protected io.lettuce.core.api.sync.RedisStringCommands<byte[],byte[]>getRedisStringCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)protected abstract <T> java.util.Optional<T>getValue(io.micronaut.core.type.Argument<T> requiredType, byte[] serializedKey)voidput(java.lang.Object key, java.lang.Object value)<T> java.util.Optional<T>putIfAbsent(java.lang.Object key, T value)protected <T> voidputValue(byte[] serializedKey, java.util.Optional<byte[]> serialized, ExpirationAfterWritePolicy policy, io.lettuce.core.api.sync.RedisStringCommands<byte[],byte[]> redisStringCommands, io.lettuce.core.api.sync.RedisKeyCommands<byte[],byte[]> redisKeyCommands, T value)protected abstract <T> voidputValue(byte[] serializedKey, T value)protected byte[]serializeKey(java.lang.Object key)Serialize the key.
-
-
-
Field Detail
-
INVALID_REDIS_CONNECTION_MESSAGE
public static final java.lang.String INVALID_REDIS_CONNECTION_MESSAGE
- See Also:
- Constant Field Values
-
keySerializer
protected final io.micronaut.core.serialize.ObjectSerializer keySerializer
-
valueSerializer
protected final io.micronaut.core.serialize.ObjectSerializer valueSerializer
-
redisCacheConfiguration
protected final RedisCacheConfiguration redisCacheConfiguration
-
expireAfterWritePolicy
protected final ExpirationAfterWritePolicy expireAfterWritePolicy
-
expireAfterAccess
protected final java.lang.Long expireAfterAccess
-
-
Constructor Detail
-
AbstractRedisCache
protected AbstractRedisCache(DefaultRedisCacheConfiguration defaultRedisCacheConfiguration, RedisCacheConfiguration redisCacheConfiguration, io.micronaut.core.convert.ConversionService<?> conversionService, io.micronaut.context.BeanLocator beanLocator)
-
-
Method Detail
-
get
public <T> java.util.Optional<T> get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)- Specified by:
getin interfaceio.micronaut.cache.SyncCache<C>
-
put
public void put(java.lang.Object key, java.lang.Object value)- Specified by:
putin interfaceio.micronaut.cache.SyncCache<C>
-
putIfAbsent
public <T> java.util.Optional<T> putIfAbsent(java.lang.Object key, T value)- Specified by:
putIfAbsentin interfaceio.micronaut.cache.SyncCache<C>
-
get
protected <T> T get(byte[] key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier, io.lettuce.core.api.sync.RedisStringCommands<byte[],byte[]> commands)- Type Parameters:
T-- Parameters:
key-requiredType-supplier-commands-- Returns:
- value from the cache
-
getRedisStringAsyncCommands
protected io.lettuce.core.api.async.RedisStringAsyncCommands<byte[],byte[]> getRedisStringAsyncCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)
- Parameters:
connection-- Returns:
- RedisStringAsyncCommands
-
getRedisKeyAsyncCommands
protected io.lettuce.core.api.async.RedisKeyAsyncCommands<byte[],byte[]> getRedisKeyAsyncCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)
- Parameters:
connection-- Returns:
- RedisKeyAsyncCommands
-
getRedisStringCommands
protected io.lettuce.core.api.sync.RedisStringCommands<byte[],byte[]> getRedisStringCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)
- Parameters:
connection-- Returns:
- RedisStringCommands
-
getRedisKeyCommands
protected io.lettuce.core.api.sync.RedisKeyCommands<byte[],byte[]> getRedisKeyCommands(io.lettuce.core.api.StatefulConnection<byte[],byte[]> connection)
- Parameters:
connection-- Returns:
- RedisKeyCommands
-
getValue
protected abstract <T> java.util.Optional<T> getValue(io.micronaut.core.type.Argument<T> requiredType, byte[] serializedKey)- Type Parameters:
T-- Parameters:
requiredType-serializedKey-- Returns:
- Optional
-
putValue
protected abstract <T> void putValue(byte[] serializedKey, T value)- Type Parameters:
T-- Parameters:
serializedKey-value-
-
putValue
protected <T> void putValue(byte[] serializedKey, java.util.Optional<byte[]> serialized, ExpirationAfterWritePolicy policy, io.lettuce.core.api.sync.RedisStringCommands<byte[],byte[]> redisStringCommands, io.lettuce.core.api.sync.RedisKeyCommands<byte[],byte[]> redisKeyCommands, T value)- Type Parameters:
T-- Parameters:
serializedKey-serialized-policy-redisStringCommands-redisKeyCommands-value-
-
getKeysPattern
protected java.lang.String getKeysPattern()
- Returns:
- The default keys pattern.
-
serializeKey
protected byte[] serializeKey(java.lang.Object key)
Serialize the key.- Parameters:
key- The key- Returns:
- bytes of the object
-
-