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[]>>,java.lang.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 ofSyncCachefor Lettuce / Redis.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classRedisCache.RedisAsyncCacheRedis Async cache implementation.
-
Field Summary
-
Fields inherited from class io.micronaut.configuration.lettuce.cache.AbstractRedisCache
expireAfterAccess, expireAfterWritePolicy, INVALID_REDIS_CONNECTION_MESSAGE, keySerializer, redisCacheConfiguration, valueSerializer
-
-
Constructor Summary
Constructors Constructor Description 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.micronaut.cache.AsyncCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>async()voidclose()<T> java.util.Optional<T>get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)<T> Tget(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier)protected java.lang.StringgetKeysPattern()java.lang.StringgetName()io.lettuce.core.api.StatefulConnection<byte[],byte[]>getNativeCache()protected <T> java.util.Optional<T>getValue(io.micronaut.core.type.Argument<T> requiredType, byte[] serializedKey)Get the value based on the parameters.voidinvalidate(java.lang.Object key)voidinvalidateAll()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, T value)Place the value in the cache.protected byte[]serializeKey(java.lang.Object key)Serialize the key.-
Methods inherited from class io.micronaut.configuration.lettuce.cache.AbstractRedisCache
get, getRedisKeyAsyncCommands, getRedisKeyCommands, getRedisStringAsyncCommands, getRedisStringCommands, putValue
-
-
-
-
Constructor Detail
-
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 Detail
-
getName
public java.lang.String getName()
-
getNativeCache
public io.lettuce.core.api.StatefulConnection<byte[],byte[]> getNativeCache()
-
get
public <T> T get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier)
-
invalidate
public void invalidate(java.lang.Object key)
-
invalidateAll
public void invalidateAll()
-
async
public io.micronaut.cache.AsyncCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>> async()
-
getValue
protected <T> java.util.Optional<T> getValue(io.micronaut.core.type.Argument<T> requiredType, byte[] serializedKey)Get the value based on the parameters.- Specified by:
getValuein 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:
putValuein classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>- Type Parameters:
T- type of the value- Parameters:
serializedKey- serializedKeyvalue- value
-
get
@NonNull 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<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>- Overrides:
getin classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>
-
put
public void put(java.lang.Object key, java.lang.Object value)- Specified by:
putin interfaceio.micronaut.cache.SyncCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>- Overrides:
putin classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>
-
putIfAbsent
@NonNull public <T> java.util.Optional<T> putIfAbsent(java.lang.Object key, T value)- Specified by:
putIfAbsentin interfaceio.micronaut.cache.SyncCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>- Overrides:
putIfAbsentin classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>
-
getKeysPattern
protected java.lang.String getKeysPattern()
- Overrides:
getKeysPatternin classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>- Returns:
- The default keys pattern.
-
serializeKey
protected byte[] serializeKey(java.lang.Object key)
Description copied from class:AbstractRedisCacheSerialize the key.- Overrides:
serializeKeyin classAbstractRedisCache<io.lettuce.core.api.StatefulConnection<byte[],byte[]>>- Parameters:
key- The key- Returns:
- bytes of the object
-
close
@PreDestroy public void close()
-
-