Class RedisConnectionPoolCache

  • All Implemented Interfaces:
    io.micronaut.cache.Cache<io.lettuce.core.support.AsyncPool<io.lettuce.core.api.StatefulConnection<byte[],​byte[]>>>, io.micronaut.cache.SyncCache<io.lettuce.core.support.AsyncPool<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="false")
    public class RedisConnectionPoolCache
    extends AbstractRedisCache<io.lettuce.core.support.AsyncPool<io.lettuce.core.api.StatefulConnection<byte[],​byte[]>>>
    An implementation of SyncCache for Lettuce / Redis using connection pooling.
    Since:
    5.3.0
    • Constructor Detail

      • RedisConnectionPoolCache

        public RedisConnectionPoolCache​(DefaultRedisCacheConfiguration defaultRedisCacheConfiguration,
                                        RedisCacheConfiguration redisCacheConfiguration,
                                        io.micronaut.core.convert.ConversionService<?> conversionService,
                                        io.micronaut.context.BeanLocator beanLocator,
                                        io.lettuce.core.support.AsyncPool<io.lettuce.core.api.StatefulConnection<byte[],​byte[]>> asyncPool)
        Creates a new redis cache for the given arguments.
        Parameters:
        defaultRedisCacheConfiguration - The default configuration
        redisCacheConfiguration - The configuration
        conversionService - The conversion service
        beanLocator - The bean locator used to discover the redis connection from the configuration
        asyncPool - Redis async pool
    • Method Detail

      • getName

        public java.lang.String getName()
      • getNativeCache

        public io.lettuce.core.support.AsyncPool<io.lettuce.core.api.StatefulConnection<byte[],​byte[]>> getNativeCache()
      • get

        public <T> T get​(@NonNull
                         java.lang.Object key,
                         @NonNull
                         io.micronaut.core.type.Argument<T> requiredType,
                         @NonNull
                         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.support.AsyncPool<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:
        getValue in class AbstractRedisCache<io.lettuce.core.support.AsyncPool<io.lettuce.core.api.StatefulConnection<byte[],​byte[]>>>
        Type Parameters:
        T - type of the argument
        Parameters:
        requiredType - requiredType
        serializedKey - serializedKey
        Returns:
        value
      • putValue

        protected <T> void putValue​(byte[] serializedKey,
                                    T value)
        Place the value in the cache.
        Specified by:
        putValue in class AbstractRedisCache<io.lettuce.core.support.AsyncPool<io.lettuce.core.api.StatefulConnection<byte[],​byte[]>>>
        Type Parameters:
        T - type of the value
        Parameters:
        serializedKey - serializedKey
        value - value
      • close

        @PreDestroy
        public void close()