Class RedisCache
java.lang.Object
io.micronaut.configuration.lettuce.cache.AbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>
io.micronaut.configuration.lettuce.cache.RedisCache
- All Implemented Interfaces:
io.micronaut.cache.Cache<io.lettuce.core.api.StatefulConnection<byte[],
,byte[]>> io.micronaut.cache.SyncCache<io.lettuce.core.api.StatefulConnection<byte[],
,byte[]>> AutoCloseable
@EachBean(RedisCacheConfiguration.class)
@Requires(classes=io.micronaut.cache.SyncCache.class,
property="redis.pool.enabled",
defaultValue="false",
notEquals="true")
public class RedisCache
extends AbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>
An implementation of
SyncCache
for Lettuce / Redis.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Redis Async cache implementation. -
Field Summary
Fields inherited from class io.micronaut.configuration.lettuce.cache.AbstractRedisCache
expireAfterAccess, expireAfterWritePolicy, INVALID_REDIS_CONNECTION_MESSAGE, invalidateScanCount, keySerializer, redisCacheConfiguration, valueSerializer
-
Constructor Summary
ConstructorDescriptionRedisCache
(DefaultRedisCacheConfiguration defaultRedisCacheConfiguration, RedisCacheConfiguration redisCacheConfiguration, io.micronaut.core.convert.ConversionService conversionService, io.micronaut.context.BeanLocator beanLocator) Creates a new redis cache for the given arguments. -
Method Summary
Modifier and TypeMethodDescriptionio.micronaut.cache.AsyncCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> async()
void
close()
<T> @NonNull Optional<T>
<T> T
protected String
getName()
io.lettuce.core.api.StatefulConnection<byte[],
byte[]> protected <T> Optional<T>
getValue
(io.micronaut.core.type.Argument<T> requiredType, byte[] serializedKey) Get the value based on the parameters.void
invalidate
(Object key) void
void
<T> @NonNull Optional<T>
putIfAbsent
(Object key, T value) protected <T> void
putValue
(byte[] serializedKey, T value) Place the value in the cache.protected byte[]
serializeKey
(Object key) Serialize the key.Methods inherited from class io.micronaut.configuration.lettuce.cache.AbstractRedisCache
get, getRedisKeyAsyncCommands, getRedisKeyCommands, getRedisStringAsyncCommands, getRedisStringCommands, putValue
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.cache.Cache
getCacheInfo
Methods inherited from interface io.micronaut.cache.SyncCache
get, get, getExecutorService, putIfAbsent
-
Constructor Details
-
RedisCache
public RedisCache(DefaultRedisCacheConfiguration defaultRedisCacheConfiguration, RedisCacheConfiguration redisCacheConfiguration, io.micronaut.core.convert.ConversionService conversionService, io.micronaut.context.BeanLocator beanLocator) Creates a new redis cache for the given arguments.- Parameters:
defaultRedisCacheConfiguration
- The default configurationredisCacheConfiguration
- The configurationconversionService
- The conversion servicebeanLocator
- The bean locator used to discover the redis connection from the configuration
-
-
Method Details
-
getName
-
getNativeCache
public io.lettuce.core.api.StatefulConnection<byte[],byte[]> getNativeCache() -
get
-
invalidate
-
invalidateAll
public void invalidateAll() -
async
public io.micronaut.cache.AsyncCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>> async() -
getValue
protected <T> Optional<T> getValue(io.micronaut.core.type.Argument<T> requiredType, byte[] serializedKey) Get the value based on the parameters.- Specified by:
getValue
in classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> - Type Parameters:
T
- type of the argument- Parameters:
requiredType
- requiredTypeserializedKey
- serializedKey- Returns:
- value
-
putValue
protected <T> void putValue(byte[] serializedKey, T value) Place the value in the cache.- Specified by:
putValue
in classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> - Type Parameters:
T
- type of the value- Parameters:
serializedKey
- serializedKeyvalue
- value
-
get
@NonNull public <T> @NonNull Optional<T> get(Object key, io.micronaut.core.type.Argument<T> requiredType) - Specified by:
get
in interfaceio.micronaut.cache.SyncCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> - Overrides:
get
in classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>>
-
put
- Specified by:
put
in interfaceio.micronaut.cache.SyncCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> - Overrides:
put
in classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceio.micronaut.cache.SyncCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> - Overrides:
putIfAbsent
in classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>>
-
getKeysPattern
- Overrides:
getKeysPattern
in classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> - Returns:
- The default keys pattern.
-
serializeKey
Description copied from class:AbstractRedisCache
Serialize the key.- Overrides:
serializeKey
in classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],
byte[]>> - Parameters:
key
- The key- Returns:
- bytes of the object
-
close
@PreDestroy public void close()
-