Skip to content

Cache API implementations

Spring Cache

Redisson provides various Spring Cache implementations. Each Cache instance has two important parameters: ttl and maxIdleTime. Data is stored infinitely if these settings are not defined or equal to 0.

Config example:

    @Configuration
    @ComponentScan
    @EnableCaching
    public static class Application {

        @Bean(destroyMethod="shutdown")
        RedissonClient redisson() throws IOException {
            Config config = new Config();
            config.useClusterServers()
                  .addNodeAddress("redis://127.0.0.1:7004", "redis://127.0.0.1:7001");
            return Redisson.create(config);
        }

        @Bean
        CacheManager cacheManager(RedissonClient redissonClient) {
            Map<String, CacheConfig> config = new HashMap<String, CacheConfig>();

            // create "testMap" cache with ttl = 24 minutes and maxIdleTime = 12 minutes
            config.put("testMap", new CacheConfig(24*60*1000, 12*60*1000));
            return new RedissonSpringCacheManager(redissonClient, config);
        }

    }

Cache configuration can be read from YAML configuration files:

    @Configuration
    @ComponentScan
    @EnableCaching
    public static class Application {

        @Bean(destroyMethod="shutdown")
        RedissonClient redisson(@Value("classpath:/redisson.yaml") Resource configFile) throws IOException {
            Config config = Config.fromYAML(configFile.getInputStream());
            return Redisson.create(config);
        }

        @Bean
        CacheManager cacheManager(RedissonClient redissonClient) throws IOException {
            return new RedissonSpringCacheManager(redissonClient, "classpath:/cache-config.yaml");
        }

    }

Eviction, local cache and data partitioning

Redisson provides various Spring Cache managers with two important features:

local cache - so called near cache used to speed up read operations and avoid network roundtrips. It caches Map entries on Redisson side and executes read operations up to 45x faster in comparison with common implementation. Local cache instances with the same name connected to the same pub/sub channel. This channel is used for exchanging of update/invalidate events between all instances. Local cache store doesn't use hashCode()/equals() methods of key object, instead it uses hash of serialized state.

data partitioning - although Map object is cluster compatible its content isn't scaled/partitioned across multiple Redis or Valkey master nodes in cluster. Data partitioning allows to scale available memory, read/write operations and entry eviction process for individual Map instance in cluster.

Scripted eviction

Allows to define time to live or max idle time parameters per map entry. Eviction is done on Redisson side through a custom scheduled task which removes expired entries using Lua script. Eviction task is started once per unique object name at the moment of getting Map instance. If instance isn't used and has expired entries it should be get again to start the eviction process. This leads to extra Redis or Valkey calls and eviction task per unique map object name.

Entries are cleaned time to time by org.redisson.eviction.EvictionScheduler. By default, it removes 100 expired entries at a time. This can be changed through cleanUpKeysAmount setting. Task launch time tuned automatically and depends on expired entries amount deleted in previous time and varies between 5 second to 30 minutes by default. This time interval can be changed through minCleanUpDelay and maxCleanUpDelay. For example, if clean task deletes 100 entries each time it will be executed every 5 seconds (minimum execution delay). But if current expired entries amount is lower than previous one then execution delay will be increased by 1.5 times and decreased otherwise.

Available implementations:

Class name Local
cache
Data
partitioning
Ultra-fast
read/write
RedissonSpringCacheManager
open-source version
RedissonSpringCacheManager
Redisson PRO version
✔️
RedissonSpringLocalCachedCacheManager
available only in Redisson PRO
✔️ ✔️
RedissonClusteredSpringCacheManager
available only in Redisson PRO
✔️ ✔️
RedissonClusteredSpringLocalCachedCacheManager
available only in Redisson PRO
✔️ ✔️ ✔️

Advanced eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis or Valkey side.

Available implementations:

Class name Local
cache
Data
partitioning
Ultra-fast
read/write
RedissonSpringCacheV2Manager
available only in Redisson PRO
✔️ ✔️
RedissonSpringLocalCachedCacheV2Manager
available only in Redisson PRO
✔️ ✔️ ✔️

Native eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis side.
Requires Redis 7.4+.

Available implementations:

Class name Local
cache
Data
partitioning
Ultra-fast
read/write
RedissonSpringCacheNativeManager
open-source version
RedissonSpringCacheNativeManager
Redisson PRO version
✔️
RedissonSpringLocalCachedCacheNativeManager
available only in Redisson PRO
✔️ ✔️
RedissonClusteredSpringCacheNativeManager
available only in Redisson PRO
✔️ ✔️

Local cache

Follow options object can be supplied during local cached managers initialization:

LocalCachedMapOptions options = LocalCachedMapOptions.defaults()

// Defines whether to store a cache miss into the local cache.
// Default value is false.
.storeCacheMiss(false);

// Defines store mode of cache data.
// Follow options are available:
// LOCALCACHE - store data in local cache only.
// LOCALCACHE_REDIS - store data in both Redis or Valkey and local cache.
.storeMode(StoreMode.LOCALCACHE_REDIS)

// Defines Cache provider used as local cache store.
// Follow options are available:
// REDISSON - uses Redisson own implementation
// CAFFEINE - uses Caffeine implementation
.cacheProvider(CacheProvider.REDISSON)

 // Defines local cache eviction policy.
 // Follow options are available:
 // LFU - Counts how often an item was requested. Those that are used least often are discarded first.
 // LRU - Discards the least recently used items first
 // SOFT - Uses weak references, entries are removed by GC
 // WEAK - Uses soft references, entries are removed by GC
 // NONE - No eviction
.evictionPolicy(EvictionPolicy.NONE)

 // If cache size is 0 then local cache is unbounded.
.cacheSize(1000)

 // Used to load missed updates during any connection failures to Redis. 
 // Since, local cache updates can't be get in absence of connection to Redis. 
 // Follow reconnection strategies are available:
 // CLEAR - Clear local cache if map instance has been disconnected for a while.
 // LOAD - Store invalidated entry hash in invalidation log for 10 minutes
 //        Cache keys for stored invalidated entry hashes will be removed 
 //        if LocalCachedMap instance has been disconnected less than 10 minutes
 //        or whole cache will be cleaned otherwise.
 // NONE - Default. No reconnection handling
.reconnectionStrategy(ReconnectionStrategy.NONE)

 // Used to synchronize local cache changes.
 // Follow sync strategies are available:
 // INVALIDATE - Default. Invalidate cache entry across all LocalCachedMap instances on map entry change
 // UPDATE - Insert/update cache entry across all LocalCachedMap instances on map entry change
 // NONE - No synchronizations on map changes
.syncStrategy(SyncStrategy.INVALIDATE)

 // time to live for each map entry in local cache
.timeToLive(10000)
 // or
.timeToLive(10, TimeUnit.SECONDS)

 // max idle time for each map entry in local cache
.maxIdle(10000)
 // or
.maxIdle(10, TimeUnit.SECONDS);

Each Spring Cache instance has two important parameters: ttl and maxIdleTime and stores data infinitely if they are not defined or equal to 0.

Complete config example:

@Configuration
@ComponentScan
@EnableCaching
public static class Application {

    @Bean(destroyMethod="shutdown")
    RedissonClient redisson() throws IOException {
        Config config = new Config();
        config.useClusterServers()
              .addNodeAddress("redis://127.0.0.1:7004", "redis://127.0.0.1:7001");
        return Redisson.create(config);
    }

    @Bean
    CacheManager cacheManager(RedissonClient redissonClient) {
        Map<String, CacheConfig> config = new HashMap<String, CacheConfig>();

        // define local cache settings for "testMap" cache.
        // ttl = 48 minutes and maxIdleTime = 24 minutes for local cache entries
        LocalCachedMapOptions options = LocalCachedMapOptions.defaults()
            .evictionPolicy(EvictionPolicy.LFU)
            .timeToLive(48, TimeUnit.MINUTES)
            .maxIdle(24, TimeUnit.MINUTES);
            .cacheSize(1000);

        // create "testMap" Redis or Valkey cache with ttl = 24 minutes and maxIdleTime = 12 minutes
        LocalCachedCacheConfig cfg = new LocalCachedCacheConfig(24*60*1000, 12*60*1000, options);
        // Max size of map stored in Redis
        cfg.setMaxSize(2000);
        config.put("testMap", cfg);

        return new RedissonSpringLocalCachedCacheManager(redissonClient, config);
        // or 
        return new RedissonSpringLocalCachedCacheNativeManager(redissonClient, config);
        // or 
        return new RedissonSpringLocalCachedCacheV2Manager(redissonClient, config);
        // or 
        return new RedissonClusteredSpringLocalCachedCacheManager(redissonClient, config);
    }

}

Cache configuration could be read from YAML configuration files:

    @Configuration
    @ComponentScan
    @EnableCaching
    public static class Application {

        @Bean(destroyMethod="shutdown")
        RedissonClient redisson(@Value("classpath:/redisson.yaml") Resource configFile) throws IOException {
            Config config = Config.fromYAML(configFile.getInputStream());
            return Redisson.create(config);
        }

        @Bean
        CacheManager cacheManager(RedissonClient redissonClient) throws IOException {
            return new RedissonSpringLocalCachedCacheManager(redissonClient, "classpath:/cache-config.yaml");
        }

    }

YAML config format

Below is the configuration of Spring Cache with name testMap in YAML format:

---
testMap:
  ttl: 1440000
  maxIdleTime: 720000
  localCacheOptions:
    invalidationPolicy: "ON_CHANGE"
    evictionPolicy: "NONE"
    cacheSize: 0
    timeToLiveInMillis: 0
    maxIdleInMillis: 0

Please note: localCacheOptions settings are available for org.redisson.spring.cache.RedissonSpringLocalCachedCacheManager and org.redisson.spring.cache.RedissonSpringClusteredLocalCachedCacheManager classes only.

Hibernate Cache

Redisson implements Hibernate 2nd level Cache provider based on Redis.
All Hibernate cache strategies are supported: READ_ONLY, NONSTRICT_READ_WRITE, READ_WRITE and TRANSACTIONAL.

Compatible with Hibernate 4.x, 5.1.x, 5.2.x, 5.3.3+ up to 5.6.x and 6.0.2+ up to 6.x.x

Eviction, local cache and data partitioning

Redisson provides various Hibernate Cache factories including those with features below:

local cache - so called near cache, which is useful for use cases when Hibernate Cache used mostly for read operations and/or network roundtrips are undesirable. It caches Map entries on Redisson side and executes read operations up to 5x faster in comparison with common implementation. Local cache instances with the same name connected to the same pub/sub channel. This channel is used for exchanging of update/invalidate events between all instances. Cache store doesn't use hashCode()/equals() methods of key object, instead it uses hash of serialized state.

data partitioning - although all implementations are cluster compatible thier content isn't scaled/partitioned across multiple Redis or Valkey master nodes in cluster. Data partitioning allows to scale available memory, read/write operations and entry eviction process for individual Hibernate Cache instance in Redis or Valkey cluster.

1. Scripted eviction

Allows to define time to live or max idle time parameters per map entry. Eviction is done on Redisson side through a custom scheduled task which removes expired entries using Lua script. Eviction task is started once per unique object name at the moment of getting Map instance. If instance isn't used and has expired entries it should be get again to start the eviction process. This leads to extra Redis or Valkey calls and eviction task per unique map object name.

Entries are cleaned time to time by org.redisson.eviction.EvictionScheduler. By default, it removes 100 expired entries at a time. This can be changed through cleanUpKeysAmount setting. Task launch time tuned automatically and depends on expired entries amount deleted in previous time and varies between 5 second to 30 minutes by default. This time interval can be changed through minCleanUpDelay and maxCleanUpDelay. For example, if clean task deletes 100 entries each time it will be executed every 5 seconds (minimum execution delay). But if current expired entries amount is lower than previous one then execution delay will be increased by 1.5 times and decreased otherwise.

Available implementations:

Class name Local cache Data
partitioning
Ultra-fast
read/write
RedissonRegionFactory
open-source version
RedissonRegionFactory
Redisson PRO version
✔️
RedissonLocalCachedRegionFactory
available only in Redisson PRO
✔️ ✔️
RedissonClusteredRegionFactory
available only in Redisson PRO
✔️ ✔️
RedissonClusteredLocalCachedRegionFactory
available only in Redisson PRO
✔️ ✔️ ✔️

2. Advanced eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis or Valkey side.

Available implementations:

Class name Local cache Data
partitioning
Ultra-fast
read/write
RedissonRegionV2Factory
available only in Redisson PRO
✔️ ✔️
RedissonLocalCachedV2RegionFactory
available only in Redisson PRO
✔️ ✔️ ✔️

3. Native eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis side.
Requires Redis 7.4+.

Available implementations:

Class name Local cache Data
partitioning
Ultra-fast
read/write
RedissonRegionNativeFactory
open-source version
RedissonRegionNativeFactory
Redisson PRO version
✔️
RedissonLocalCachedNativeRegionFactory
available only in Redisson PRO
✔️ ✔️
RedissonClusteredNativeRegionFactory
available only in Redisson PRO
✔️ ✔️

Usage

1. Add redisson-hibernate dependency into your project:

Maven

     <dependency>
         <groupId>org.redisson</groupId>
         <!-- for Hibernate v4.x -->
         <artifactId>redisson-hibernate-4</artifactId>
         <!-- for Hibernate v5.0.x - v5.1.x -->
         <artifactId>redisson-hibernate-5</artifactId>
         <!-- for Hibernate v5.2.x -->
         <artifactId>redisson-hibernate-52</artifactId>
         <!-- for Hibernate v5.3.3+ - v5.6.x -->
         <artifactId>redisson-hibernate-53</artifactId>
         <!-- for Hibernate v6.0.2+ - v6.x.x -->
         <artifactId>redisson-hibernate-6</artifactId>
         <version>3.36.0</version>
     </dependency>

Gradle

     // for Hibernate v4.x
     compile 'org.redisson:redisson-hibernate-4:3.36.0'
     // for Hibernate v5.0.x - v5.1.x
     compile 'org.redisson:redisson-hibernate-5:3.36.0'
     // for Hibernate v5.2.x
     compile 'org.redisson:redisson-hibernate-52:3.36.0'
     // for Hibernate v5.3.3+ - v5.6.x
     compile 'org.redisson:redisson-hibernate-53:3.36.0'
     // for Hibernate v6.0.2+ - v6.x.x
     compile 'org.redisson:redisson-hibernate-6:3.36.0'

2. Specify hibernate cache settings

Define Redisson Region Cache Factory:

<!-- Redisson Region Cache factory -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonRegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonRegionV2Factory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonLocalCachedRegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonLocalCachedV2RegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonClusteredRegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonClusteredLocalCachedRegionFactory" />

By default each Region Factory creates own Redisson instance. For multiple applications, using the same Redis or Valkey setup and deployed in the same JVM, amount of Redisson instances could be reduced using JNDI registry:

<!-- name of Redisson instance registered in JNDI -->
<property name="hibernate.cache.redisson.jndi_name" value="redisson_instance" />

<!-- JNDI Redisson Region Cache factory -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonRegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonRegionV2Factory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonLocalCachedRegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonLocalCachedV2RegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonClusteredRegionFactory" />
<!-- or -->
<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonClusteredLocalCachedRegionFactory" />
<!-- 2nd level cache activation -->
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />

<!-- Redisson can fallback on database if Redis or Valkey cache is unavailable -->
<property name="hibernate.cache.redisson.fallback" value="true" />

<!-- Redisson YAML config (located in filesystem or classpath) -->
<property name="hibernate.cache.redisson.config" value="/redisson.yaml" />

Cache settings

Redisson allows to define follow cache settings per entity, collection, naturalid, query and timestamp regions:

REGION_NAME - is a name of region which is defined in @Cache annotation otherwise it's a fully qualified class name.

Parameter hibernate.cache.redisson.[REGION_NAME].eviction.max_entries
Description Max size of cache. Superfluous entries in Redis or Valkey are evicted using LRU algorithm.
0 value means unbounded cache.
Default value 0
Parameter hibernate.cache.redisson.[REGION_NAME].expiration.time_to_live
Description Time to live per cache entry in Redis. Defined in milliseconds.
0 value means this setting doesn't affect expiration.
Default value 0
Parameter hibernate.cache.redisson.[REGION_NAME].expiration.max_idle_time
Description Max idle time per cache entry in Redis. Defined in milliseconds.
0 value means this setting doesn't affect expiration.
Default value 0
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.cache_provider
Description Cache provider used as local cache store.
REDISSON and CAFFEINE providers are available.
Default value REDISSON
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.store_mode
Description Store mode of cache data.
LOCALCACHE - store data in local cache only and use Redis or Valkey only for data update/invalidation
LOCALCACHE_REDIS - store data in both Redis or Valkey and local cache
Default value LOCALCACHE
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.max_idle_time
Description Max idle time per entry in local cache. Defined in milliseconds.
0 value means this setting doesn't affect expiration
Default value 0
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.time_to_live
Description Time to live per entry in local cache. Defined in milliseconds.
0 value means this setting doesn't affect expiration
Default value 0
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.eviction_policy
Description Eviction policy applied to local cache entries when cache size limit reached.
LFU, LRU, SOFT, WEAK and NONE policies are available.
Default value NONE
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.sync_strategy
Description Sync strategy used to synchronize local cache changes across all instances.
INVALIDATE - Invalidate cache entry across all LocalCachedMap instances on map entry change
UPDATE - Update cache entry across all LocalCachedMap instances on map entry change
NONE - No synchronizations on map changes
Default value INVALIDATE
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.reconnection_strategy
Description Reconnection strategy used to load missed local cache updates through Hibernate during any connection failures to Redis.
CLEAR - Clear local cache if map instance has been disconnected for a while
LOAD - Store invalidated entry hash in invalidation log for 10 minutes. Cache keys for stored invalidated entry hashes will be removed if LocalCachedMap instance has been disconnected less than 10 minutes or whole cache will be cleaned otherwise
NONE - No reconnection handling
Default value NONE
Parameter hibernate.cache.redisson.[REGION_NAME].localcache.size
Description Max size of local cache. Superfluous entries in Redis or Valkey are evicted using defined eviction policy.
0 value means unbounded cache.
Default value 0

NOTE: hibernate.cache.redisson.[REGION_NAME].localcache.* settings are available for RedissonClusteredLocalCachedRegionFactory and RedissonLocalCachedRegionFactory classes only.

Default cache settings

Default region configuration used for all caches not specified in configuration:

<!-- cache definition applied to all caches in entity region -->
<property name="hibernate.cache.redisson.entity.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.entity.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.entity.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.entity.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.entity.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.entity.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.entity.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.entity.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.entity.localcache.size" value="5000" />

<!-- cache definition applied to all caches in collection region -->
<property name="hibernate.cache.redisson.collection.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.collection.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.collection.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.collection.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.collection.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.collection.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.collection.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.collection.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.collection.localcache.size" value="5000" />

<!-- cache definition applied to all caches in naturalid region -->
<property name="hibernate.cache.redisson.naturalid.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.naturalid.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.naturalid.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.naturalid.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.naturalid.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.naturalid.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.naturalid.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.naturalid.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.naturalid.localcache.size" value="5000" />

<!-- cache definition applied to all caches in query region -->
<property name="hibernate.cache.redisson.query.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.query.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.query.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.query.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.query.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.query.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.query.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.query.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.query.localcache.size" value="5000" />

<!-- cache definition for timestamps region -->
<property name="hibernate.cache.redisson.timestamps.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.timestamps.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.timestamps.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.timestamps.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.timestamps.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.timestamps.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.timestamps.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.timestamps.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.timestamps.localcache.size" value="5000" />

Overriding the default configuration

Configuration per entity/collection/naturalid/query region overrides default configuration:

<!-- cache definition for entity region. Example region name: "my_object" -->
<property name="hibernate.cache.redisson.my_object.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.my_object.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.my_object.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.my_object.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.my_object.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.my_object.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.my_object.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.my_object.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.my_object.localcache.size" value="5000" />

<!-- cache definition for collection region. Example region name: "my_list" -->
<property name="hibernate.cache.redisson.my_list.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.my_list.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.my_list.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.my_list.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.my_list.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.my_list.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.my_list.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.my_list.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.my_list.localcache.size" value="5000" />

<!-- cache definition for naturalid region. Suffixed by ##NaturalId. Example region name: "my_object" -->
<property name="hibernate.cache.redisson.my_object##NaturalId.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.my_object##NaturalId.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.my_object##NaturalId.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.my_object##NaturalId.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.my_object##NaturalId.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.my_object##NaturalId.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.my_object##NaturalId.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.my_object##NaturalId.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.my_object##NaturalId.localcache.size" value="5000" />

<!-- cache definition for query region. Example region name: "my_query" -->
<property name="hibernate.cache.redisson.my_query.eviction.max_entries" value="10000" />
<property name="hibernate.cache.redisson.my_query.expiration.time_to_live" value="600000" />
<property name="hibernate.cache.redisson.my_query.expiration.max_idle_time" value="300000" />

<property name="hibernate.cache.redisson.my_query.localcache.max_idle_time" value="300000" />
<property name="hibernate.cache.redisson.my_query.localcache.time_to_live" value="300000" />
<property name="hibernate.cache.redisson.my_query.localcache.eviction_policy" value="LRU" />
<property name="hibernate.cache.redisson.my_query.localcache.sync_strategy" value="INVALIDATE" />
<property name="hibernate.cache.redisson.my_query.localcache.reconnection_strategy" value="CLEAR" />
<property name="hibernate.cache.redisson.my_query.localcache.size" value="5000" />

JCache API (JSR-107)

Redisson provides an implementation of JCache API (JSR-107) for Redis.

Below are examples of JCache API usage.

1. Using default config located at /redisson-jcache.yaml:

MutableConfiguration<String, String> config = new MutableConfiguration<>();

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", config);

2. Using config file with custom location:

MutableConfiguration<String, String> config = new MutableConfiguration<>();

// yaml config
URI redissonConfigUri = getClass().getResource("redisson-jcache.yaml").toURI();
CacheManager manager = Caching.getCachingProvider().getCacheManager(redissonConfigUri, null);
Cache<String, String> cache = manager.createCache("namedCache", config);

3. Using Redisson's config object:

MutableConfiguration<String, String> jcacheConfig = new MutableConfiguration<>();

Config redissonCfg = ...
Configuration<String, String> config = RedissonConfiguration.fromConfig(redissonCfg, jcacheConfig);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", config);

4. Using Redisson instance object:

MutableConfiguration<String, String> jcacheConfig = new MutableConfiguration<>();

RedissonClient redisson = ...
Configuration<String, String> config = RedissonConfiguration.fromInstance(redisson, jcacheConfig);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", config);

Read more here about Redisson configuration.

Provided implementation fully passes TCK tests. Here is the test module.

Asynchronous, Reactive and RxJava3 interfaces

Along with usual JCache API, Redisson provides Asynchronous, Reactive and RxJava3 API.

Asynchronous interface. Each method returns org.redisson.api.RFuture object.
Example:

MutableConfiguration<String, String> config = new MutableConfiguration<>();

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("myCache", config);

CacheAsync<String, String> asyncCache = cache.unwrap(CacheAsync.class);
RFuture<Void> putFuture = asyncCache.putAsync("1", "2");
RFuture<String> getFuture = asyncCache.getAsync("1");

Reactive interface. Each method returns reactor.core.publisher.Mono object.
Example:

MutableConfiguration<String, String> config = new MutableConfiguration<>();

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("myCache", config);

CacheReactive<String, String> reactiveCache = cache.unwrap(CacheReactive.class);
Mono<Void> putFuture = reactiveCache.put("1", "2");
Mono<String> getFuture = reactiveCache.get("1");

RxJava3 interface. Each method returns one of the following object: io.reactivex.Completable, io.reactivex.Single, io.reactivex.Maybe.
Example:

MutableConfiguration<String, String> config = new MutableConfiguration<>();

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("myCache", config);

CacheRx<String, String> rxCache = cache.unwrap(CacheRx.class);
Completable putFuture = rxCache.put("1", "2");
Maybe<String> getFuture = rxCache.get("1");

Local cache and data partitioning

Redisson provides JCache implementations with two important features:

local cache - so called near cache used to speed up read operations and avoid network roundtrips. It caches JCache entries on Redisson side and executes read operations up to 45x faster in comparison with common implementation. Local cache instances with the same name connected to the same pub/sub channel. This channel is used for exchanging of update/invalidate events between all instances. Local cache store doesn't use hashCode()/equals() methods of key object, instead it uses hash of serialized state.

data partitioning - although JCache instance is cluster compatible its content isn't scaled/partitioned across multiple Redis or Valkey master nodes in cluster. Data partitioning allows to scale available memory, read/write operations and entry eviction process for individual JCache instance in Redis or Valkey cluster.

fallback mode - if set to true and Redis or Valkey is down the errors won't be thrown allowing application continue to operate without Redis.

Below is the complete list of available managers:

Local
cache
Data
partitioning
Ultra-fast
read/write
Fallback
mode
JCache
open-source version
JCache
Redisson PRO version
✔️ ✔️
JCache with local cache
available only in Redisson PRO
✔️ ✔️ ✔️
JCache with data partitioning
available only in Redisson PRO
✔️ ✔️ ✔️
JCache with local cache and data partitioning
available only in Redisson PRO
✔️ ✔️ ✔️ ✔️

Local cache configuration

      LocalCacheConfiguration<String, String> configuration = new LocalCacheConfiguration<>()

      // Defines whether to store a cache miss into the local cache.
      // Default value is false.
      .storeCacheMiss(false);

      // Defines store mode of cache data.
      // Follow options are available:
      // LOCALCACHE - store data in local cache only and use Redis or Valkey only for data update/invalidation.
      // LOCALCACHE_REDIS - store data in both Redis or Valkey and local cache.
      .storeMode(StoreMode.LOCALCACHE_REDIS)

      // Defines Cache provider used as local cache store.
      // Follow options are available:
      // REDISSON - uses Redisson own implementation
      // CAFFEINE - uses Caffeine implementation
      .cacheProvider(CacheProvider.REDISSON)

      // Defines local cache eviction policy.
      // Follow options are available:
      // LFU - Counts how often an item was requested. Those that are used least often are discarded first.
      // LRU - Discards the least recently used items first
      // SOFT - Uses weak references, entries are removed by GC
      // WEAK - Uses soft references, entries are removed by GC
      // NONE - No eviction
     .evictionPolicy(EvictionPolicy.NONE)

      // If cache size is 0 then local cache is unbounded.
     .cacheSize(1000)

      // Used to load missed updates during any connection failures to Redis. 
      // Since, local cache updates can't be get in absence of connection to Redis. 
      // Follow reconnection strategies are available:
      // CLEAR - Clear local cache if map instance has been disconnected for a while.
      // LOAD - Store invalidated entry hash in invalidation log for 10 minutes
      //        Cache keys for stored invalidated entry hashes will be removed 
      //        if LocalCachedMap instance has been disconnected less than 10 minutes
      //        or whole cache will be cleaned otherwise.
      // NONE - Default. No reconnection handling
     .reconnectionStrategy(ReconnectionStrategy.NONE)

      // Used to synchronize local cache changes.
      // Follow sync strategies are available:
      // INVALIDATE - Default. Invalidate cache entry across all LocalCachedMap instances on map entry change
      // UPDATE - Insert/update cache entry across all LocalCachedMap instances on map entry change
      // NONE - No synchronizations on map changes
     .syncStrategy(SyncStrategy.INVALIDATE)

      // time to live for each map entry in local cache
     .timeToLive(10000)
      // or
     .timeToLive(10, TimeUnit.SECONDS)

      // max idle time for each map entry in local cache
     .maxIdle(10000)
      // or
     .maxIdle(10, TimeUnit.SECONDS);

Usage example:

LocalCacheConfiguration<String, String> config = new LocalCacheConfiguration<>();
                .setEvictionPolicy(EvictionPolicy.LFU)
                .setTimeToLive(48, TimeUnit.MINUTES)
                .setMaxIdle(24, TimeUnit.MINUTES);
                .setCacheSize(1000);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("myCache", config);

// or

URI redissonConfigUri = getClass().getResource("redisson-jcache.yaml").toURI();
CacheManager manager = Caching.getCachingProvider().getCacheManager(redissonConfigUri, null);
Cache<String, String> cache = manager.createCache("myCache", config);

// or 

Config redissonCfg = ...
Configuration<String, String> rConfig = RedissonConfiguration.fromConfig(redissonCfg, config);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", rConfig);

Data partitioning

Usage examples:

ClusteredConfiguration<String, String> config = new ClusteredConfiguration<>();

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("myCache", config);

// or

URI redissonConfigUri = getClass().getResource("redisson-jcache.yaml").toURI();
CacheManager manager = Caching.getCachingProvider().getCacheManager(redissonConfigUri, null);
Cache<String, String> cache = manager.createCache("myCache", config);

// or 

Config redissonCfg = ...
Configuration<String, String> rConfig = RedissonConfiguration.fromConfig(redissonCfg, config);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", rConfig);

Local cache with data partitioning configuration

      ClusteredLocalCacheConfiguration<String, String> configuration = new ClusteredLocalCacheConfiguration<>()

      // Defines whether to store a cache miss into the local cache.
      // Default value is false.
      .storeCacheMiss(false);

      // Defines store mode of cache data.
      // Follow options are available:
      // LOCALCACHE - store data in local cache only and use Redis or Valkey only for data update/invalidation.
      // LOCALCACHE_REDIS - store data in both Redis or Valkey and local cache.
      .storeMode(StoreMode.LOCALCACHE_REDIS)

      // Defines Cache provider used as local cache store.
      // Follow options are available:
      // REDISSON - uses Redisson own implementation
      // CAFFEINE - uses Caffeine implementation
      .cacheProvider(CacheProvider.REDISSON)

      // Defines local cache eviction policy.
      // Follow options are available:
      // LFU - Counts how often an item was requested. Those that are used least often are discarded first.
      // LRU - Discards the least recently used items first
      // SOFT - Uses weak references, entries are removed by GC
      // WEAK - Uses soft references, entries are removed by GC
      // NONE - No eviction
     .evictionPolicy(EvictionPolicy.NONE)

      // If cache size is 0 then local cache is unbounded.
     .cacheSize(1000)

      // Used to load missed updates during any connection failures to Redis. 
      // Since, local cache updates can't be get in absence of connection to Redis. 
      // Follow reconnection strategies are available:
      // CLEAR - Clear local cache if map instance has been disconnected for a while.
      // LOAD - Store invalidated entry hash in invalidation log for 10 minutes
      //        Cache keys for stored invalidated entry hashes will be removed 
      //        if LocalCachedMap instance has been disconnected less than 10 minutes
      //        or whole cache will be cleaned otherwise.
      // NONE - Default. No reconnection handling
     .reconnectionStrategy(ReconnectionStrategy.NONE)

      // Used to synchronize local cache changes.
      // Follow sync strategies are available:
      // INVALIDATE - Default. Invalidate cache entry across all LocalCachedMap instances on map entry change
      // UPDATE - Insert/update cache entry across all LocalCachedMap instances on map entry change
      // NONE - No synchronizations on map changes
     .syncStrategy(SyncStrategy.INVALIDATE)

      // time to live for each map entry in local cache
     .timeToLive(10000)
      // or
     .timeToLive(10, TimeUnit.SECONDS)

      // max idle time for each map entry in local cache
     .maxIdle(10000)
      // or
     .maxIdle(10, TimeUnit.SECONDS);

Usage examples:

ClusteredLocalCacheConfiguration<String, String> config = new ClusteredLocalCacheConfiguration<>();

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("myCache", config);

// or

URI redissonConfigUri = getClass().getResource("redisson-jcache.yaml").toURI();
CacheManager manager = Caching.getCachingProvider().getCacheManager(redissonConfigUri, null);
Cache<String, String> cache = manager.createCache("myCache", config);

// or 

Config redissonCfg = ...
Configuration<String, String> rConfig = RedissonConfiguration.fromConfig(redissonCfg, config);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", rConfig);

Open Liberty or WebSphere Liberty integration

Distributed Cache configuration example:

<library id="jCacheVendorLib">
    <file name="${shared.resource.dir}/redisson-all-3.35.0.jar"/>
</library>

<cache id="io.openliberty.cache.authentication" name="io.openliberty.cache.authentication"
    cacheManagerRef="CacheManager" />

<cacheManager id="CacheManager" uri="file:${server.config.dir}/redisson-jcache.yaml"> 
    <properties fallback="true"/>
    <cachingProvider jCacheLibraryRef="jCacheVendorLib"/>
</cacheManager>

Distributed Session persistence configuration example:

<featureManager>
    <feature>servlet-6.0</feature>
    <feature>sessionCache-1.0</feature>
</featureManager>

<httpEndpoint httpPort="${http.port}" httpsPort="${https.port}"
        id="defaultHttpEndpoint" host="*" />

<library id="jCacheVendorLib">
    <file name="${shared.resource.dir}/redisson-all-3.35.0.jar"/>
</library>

<httpSessionCache cacheManagerRef="CacheManager"/>

<cacheManager id="CacheManager" uri="file:${server.config.dir}/redisson-jcache.yaml"> 
    <properties fallback="true"/>
    <cachingProvider jCacheLibraryRef="jCacheVendorLib"/>
</cacheManager>

Settings below are available only in Redisson PRO edition.

Follow settings are available per JCache instance:

Parameter fallback
Description Skip errors if Redis or Valkey cache is unavailable
Default value false
Parameter implementation
Description Cache implementation.
cache - standard implementation
clustered-local-cache - data partitioning and local cache support
local-cache - local cache support
clustered-cache - data partitioning support
Default value cache
Parameter localcache.store_cache_miss
Description Defines whether to store a cache miss into the local cache.
Default value false
Parameter localcache.cache_provider
Description Cache provider used as local cache store.
REDISSON and CAFFEINE providers are available.
Default value REDISSON
Parameter localcache.store_mode
Description Store mode of cache data.
LOCALCACHE - store data in local cache only and use Redis or Valkey only for data update/invalidation
LOCALCACHE_REDIS - store data in both Redis or Valkey and local cache
Default value LOCALCACHE
Parameter localcache.max_idle_time
Description Max idle time per entry in local cache. Defined in milliseconds.
0 value means this setting doesn't affect expiration
Default value 0
Parameter localcache.time_to_live
Description Time to live per entry in local cache. Defined in milliseconds.
0 value means this setting doesn't affect expiration
Default value 0
Parameter localcache.eviction_policy
Description Eviction policy applied to local cache entries when cache size limit reached.
LFU, LRU, SOFT, WEAK and NONE policies are available.
Default value NONE
Parameter localcache.sync_strategy
Description Sync strategy used to synchronize local cache changes across all instances.
INVALIDATE - Invalidate cache entry across all LocalCachedMap instances on map entry change
UPDATE - Update cache entry across all LocalCachedMap instances on map entry change
NONE - No synchronizations on map changes
Default value INVALIDATE
Parameter localcache.reconnection_strategy
Description Reconnection strategy used to load missed local cache updates through Hibernate during any connection failures to Redis.
CLEAR - Clear local cache if map instance has been disconnected for a while
LOAD - Store invalidated entry hash in invalidation log for 10 minutes. Cache keys for stored invalidated entry hashes will be removed if LocalCachedMap instance has been disconnected less than 10 minutes or whole cache will be cleaned otherwise
NONE - No reconnection handling
Default value NONE
Parameter localcache.size
Description Max size of local cache. Superfluous entries in Redis or Valkey are evicted using defined eviction policy.
0 value means unbounded cache.
Default value 0

MyBatis Cache

Redisson implements MyBatis Cache based on Redis.

Compatible with MyBatis 3.0.0+

Eviction, local cache and data partitioning

Redisson provides multiple MyBatis Cache implementations which support features below:

local cache - so called near cache used to speed up read operations and avoid network roundtrips. It caches Map entries on Redisson side and executes read operations up to 45x faster in comparison with common implementation. Local cache instances with the same name connected to the same pub/sub channel. This channel is used for exchanging of update/invalidate events between all instances. Local cache store doesn't use hashCode()/equals() methods of key object, instead it uses hash of serialized state.

data partitioning - although Map object is cluster compatible its content isn't scaled/partitioned across multiple Redis or Valkey master nodes in cluster. Data partitioning allows to scale available memory, read/write operations and entry eviction process for individual Map instance in Redis or Valkey cluster.

1. Scripted eviction

Allows to define time to live or max idle time parameters per entry. Eviction is done on Redisson side through a custom scheduled task which removes expired entries using Lua script. Eviction task is started once per unique object name at the moment of getting Map instance. If instance isn't used and has expired entries it should be get again to start the eviction process. This leads to extra Redis or Valkey calls and eviction task per unique map object name.

Entries are cleaned time to time by org.redisson.eviction.EvictionScheduler. By default, it removes 100 expired entries at a time. This can be changed through cleanUpKeysAmount setting. Task launch time tuned automatically and depends on expired entries amount deleted in previous time and varies between 5 second to 30 minutes by default. This time interval can be changed through minCleanUpDelay and maxCleanUpDelay. For example, if clean task deletes 100 entries each time it will be executed every 5 seconds (minimum execution delay). But if current expired entries amount is lower than previous one then execution delay will be increased by 1.5 times and decreased otherwise.

Available implementations:

Class name Local
cache
Data
partitioning
Ultra-fast
read/write
RedissonCache
open-source version
RedissonCache
Redisson PRO version
✔️
RedissonLocalCachedCache
available only in Redisson PRO
✔️ ✔️
RedissonClusteredCache
available only in Redisson PRO
✔️ ✔️
RedissonClusteredLocalCachedCache
available only in Redisson PRO
✔️ ✔️ ✔️

2. Advanced eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis or Valkey side.

Available implementations:

Class name Local
cache
Data
partitioning
Ultra-fast
read/write
RedissonCacheV2
available only in Redisson PRO
✔️ ✔️
RedissonLocalCachedCacheV2
available only in Redisson PRO
✔️ ✔️ ✔️

3. Native eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis side.
Requires Redis 7.4+.

Available implementations:

Class name Local
cache
Data
partitioning
Ultra-fast
read/write
RedissonCacheNative
open-source version
RedissonCacheNative
Redisson PRO version
✔️
RedissonLocalCachedCacheNative
available only in Redisson PRO
✔️ ✔️
RedissonClusteredCacheNative
available only in Redisson PRO
✔️ ✔️

Usage

1. Add redisson-mybatis dependency into your project

Maven

<dependency>
     <groupId>org.redisson</groupId>
     <artifactId>redisson-mybatis</artifactId>
     <version>3.36.0</version>
</dependency>

Gradle

compile 'org.redisson:redisson-mybatis:3.36.0'

2. Specify MyBatis cache settings

Redisson allows to define follow settings per Cache instance:

timeToLive - defines time to live per cache entry

maxIdleTime - defines max idle time per cache entry

maxSize - defines max size of entries amount stored in Redis

localCacheProvider - cache provider used as local cache store. REDISSON and CAFFEINE providers are available. Default value: REDISSON

localCacheEvictionPolicy - local cache eviction policy. LFU, LRU, SOFT, WEAK and NONE eviction policies are available.

localCacheSize - local cache size. If size is 0 then local cache is unbounded.

localCacheTimeToLive - time to live in milliseconds for each map entry in local cache. If value equals to 0 then timeout is not applied.

localCacheMaxIdleTime - max idle time in milliseconds for each map entry in local cache. If value equals to 0 then timeout is not applied.

localCacheSyncStrategy - local cache sync strategy. INVALIDATE, UPDATE and NONE eviction policies are available.

redissonConfig - defines path to redisson config in YAML format

Cache definition examples:

<cache type="org.redisson.mybatis.RedissonCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<cache type="org.redisson.mybatis.RedissonCacheNative">
  <property name="timeToLive" value="200000"/>
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<cache type="org.redisson.mybatis.RedissonCacheV2">
  <property name="timeToLive" value="200000"/>
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<cache type="org.redisson.mybatis.RedissonLocalCachedCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>

  <property name="localCacheEvictionPolicy" value="LRU"/>
  <property name="localCacheSize" value="1000"/>
  <property name="localCacheTimeToLive" value="2000000"/>
  <property name="localCacheMaxIdleTime" value="1000000"/>
  <property name="localCacheSyncStrategy" value="INVALIDATE"/>

  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<cache type="org.redisson.mybatis.RedissonLocalCachedCacheV2">
  <property name="timeToLive" value="200000"/>

  <property name="localCacheEvictionPolicy" value="LRU"/>
  <property name="localCacheSize" value="1000"/>
  <property name="localCacheTimeToLive" value="2000000"/>
  <property name="localCacheMaxIdleTime" value="1000000"/>
  <property name="localCacheSyncStrategy" value="INVALIDATE"/>

  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<cache type="org.redisson.mybatis.RedissonClusteredCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<cache type="org.redisson.mybatis.RedissonClusteredLocalCachedCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>

  <property name="localCacheEvictionPolicy" value="LRU"/>
  <property name="localCacheSize" value="1000"/>
  <property name="localCacheTimeToLive" value="2000000"/>
  <property name="localCacheMaxIdleTime" value="1000000"/>
  <property name="localCacheSyncStrategy" value="INVALIDATE"/>

  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

Quarkus Cache

Eviction, local cache and data partitioning

Redisson provides various Quarkus Cache implementations with features below:

local cache - so called near cache used to speed up read operations and avoid network roundtrips. It caches Map entries on Redisson side and executes read operations up to 45x faster in comparison with common implementation. Local cache instances with the same name connected to the same pub/sub channel. This channel is used for exchanging of update/invalidate events between all instances. Local cache store doesn't use hashCode()/equals() methods of key object, instead it uses hash of serialized state.

data partitioning - although Map object is cluster compatible its content isn't scaled/partitioned across multiple Redis or Valkey master nodes in cluster. Data partitioning allows to scale available memory, read/write operations and entry eviction process for individual Map instance in cluster.

1. Scripted eviction

Allows to define time to live or max idle time parameters per map entry. Eviction is done on Redisson side through a custom scheduled task which removes expired entries using Lua script. Eviction task is started once per unique object name at the moment of getting Map instance. If instance isn't used and has expired entries it should be get again to start the eviction process. This leads to extra Redis or Valkey calls and eviction task per unique map object name.

Entries are cleaned time to time by org.redisson.eviction.EvictionScheduler. By default, it removes 100 expired entries at a time. This can be changed through cleanUpKeysAmount setting. Task launch time tuned automatically and depends on expired entries amount deleted in previous time and varies between 5 second to 30 minutes by default. This time interval can be changed through minCleanUpDelay and maxCleanUpDelay. For example, if clean task deletes 100 entries each time it will be executed every 5 seconds (minimum execution delay). But if current expired entries amount is lower than previous one then execution delay will be increased by 1.5 times and decreased otherwise.

Available implementations:

impementation
setting value
Local
cache
Data
partitioning
Ultra-fast
read/write
standard
open-source version
standard
Redisson PRO version
✔️
localcache
available only in Redisson PRO
✔️ ✔️
clustered
available only in Redisson PRO
✔️ ✔️
clustered_localcache
available only in Redisson PRO
✔️ ✔️ ✔️

2. Advanced eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis or Valkey side.

Available implementations:

impementation
setting value
Local
cache
Data
partitioning
Ultra-fast
read/write
v2
available only in Redisson PRO
✔️ ✔️
localcache_v2
available only in Redisson PRO
✔️ ✔️ ✔️

3. Native eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis side.
Requires Redis 7.4+.

Available implementations:

impementation
setting value
Local
cache
Data
partitioning
Ultra-fast
read/write
native
open-source version
native
Redisson PRO version
✔️
localcache_native
available only in Redisson PRO
✔️ ✔️
clustered_native
available only in Redisson PRO
✔️ ✔️

Usage

1. Add redisson-quarkus-cache dependency into your project

Maven

<dependency>
    <groupId>org.redisson</groupId>
    <!-- for Quarkus v3.x.x -->
    <artifactId>redisson-quarkus-30-cache</artifactId>
    <version>xVERSIONx</version>
</dependency>

Gradle

// for Quarkus v3.x.x
compile 'org.redisson:redisson-quarkus-30-cache:xVERSIONx'

2. Add settings into application.properties file

  • Basic settings

    expire-after-write - setting defines time to live of the item stored in the cache. Default value is 0.
    expire-after-access - setting defines time to live added to the item after read operation. Default value is 0.
    implementation - setting defines the type of cache used. Default value is standard.

    Below is the cache configuration example.

    quarkus.cache.type=redisson
    quarkus.cache.redisson.implementation=standard
    
    # Default configuration for all caches
    quarkus.cache.redisson.expire-after-write=5s
    quarkus.cache.redisson.expire-after-access=1s
    
    # Configuration for `sampleCache` cache
    quarkus.cache.redisson.sampleCache.expire-after-write=100s
    quarkus.cache.redisson.sampleCache.expire-after-access=10s
    
  • Local cache settings

    quarkus.cache.redisson.[CACHE_NAME].max-size - max size of this cache. Superfluous elements are evicted using LRU algorithm. If 0 the cache is unbounded. Default value is 0.

    quarkus.cache.redisson.[CACHE_NAME].cache-size - local cache size. If size is 0 then local cache is unbounded. Default value is 0.

    quarkus.cache.redisson.[CACHE_NAME].reconnection-strategy - used to load missed updates during any connection failures to Redis. Default value isCLEAR. Since, local cache updates can't be executed in absence of connection to Redis. Available values: * CLEAR - Clear local cache if map instance has been disconnected for a while. * LOAD - Store invalidated entry hash in invalidation log for 10 minutes. Cache keys for stored invalidated entry hashes will be removed if LocalCachedMap instance has been disconnected less than 10 minutes or whole cache will be cleaned otherwise. * NONE - No reconnection handling

    redisson.cache.redisson.[CACHE_NAME].sync-strategy - used to synchronize local cache changes. Default value isINVALIDATE. Available values: * INVALIDATE - Invalidate cache entry across all LocalCachedMap instances on map entry change. * UPDATE - Insert/update cache entry across all LocalCachedMap instances on map entry change. * NONE - No synchronizations on map changes.

    redisson.cache.redisson.[CACHE_NAME].eviction-policy - defines local cache eviction policy. Default value isNONE. Available values: * LRU - uses local cache with LRU (least recently used) eviction policy. * LFU - uses local cache with LFU (least frequently used) eviction policy. * SOFT - uses local cache with soft references. The garbage collector will evict items from the local cache when the JVM is running out of memory. * WEAK - uses local cache with weak references. The garbage collector will evict items from the local cache when it became weakly reachable. * NONE - doesn't use eviction policy, but timeToLive and maxIdleTime params are still working.

    redisson.cache.redisson.[CACHE_NAME].time-to-live - time to live duration of each map entry in local cache. If value equals to 0 then timeout is not applied. Default value is 0.

    redisson.cache.redisson.[CACHE_NAME].max-idle - defines max idle time duration of each map entry in local cache. If value equals to 0 then timeout is not applied. Default value is 0.

    redisson.cache.redisson.[CACHE_NAME].store-mode - defines store mode of cache data. Default value is LOCALCACHE_REDIS. Available values: * LOCALCACHE - store data in local cache only and use Redis or Valkey only for data update/invalidation
    * LOCALCACHE_REDIS - store data in both Redis or Valkey and local cache

    redisson.cache.redisson.[CACHE_NAME].cache-provider - defines Cache provider used as local cache store. Default value is REDISSON. Available values: * REDISSON - uses Redisson own implementation * CAFFEINE - uses Caffeine implementation

    redisson.cache.redisson.[CACHE_NAME].store-cache-miss - defines whether to store a cache miss into the local cache. Default value is false.

Local cache configuration example:

quarkus.cache.type=redisson
# possible values for localcache: localcache, localcache_v2, clustered_localcache
quarkus.cache.redisson.implementation=localcache

# Default configuration for all caches
quarkus.cache.redisson.expire-after-write=5s
quarkus.cache.redisson.expire-after-access=1s
quarkus.cache.redisson.cache-size=100
quarkus.cache.redisson.eviction-policy=LFU
quarkus.cache.redisson.time-to-live=10s
quarkus.cache.redisson.max-idle=5s

# Configuration for `sampleCache` cache
quarkus.cache.redisson.sampleCache.expire-after-write=100s
quarkus.cache.redisson.sampleCache.expire-after-access=10s
quarkus.cache.redisson.sampleCache.cache-size=100
quarkus.cache.redisson.sampleCache.eviction-policy=LFU
quarkus.cache.redisson.sampleCache.time-to-live=10s
quarkus.cache.redisson.sampleCache.max-idle=5s

Micronaut Cache

Eviction, local cache and data partitioning

Redisson provides various Micronaut Cache implementations with multiple important features:

local cache - so called near cache used to speed up read operations and avoid network roundtrips. It caches Map entries on Redisson side and executes read operations up to 45x faster in comparison with common implementation. Local cache instances with the same name connected to the same pub/sub channel. This channel is used for exchanging of update/invalidate events between all instances. Local cache store doesn't use hashCode()/equals() methods of key object, instead it uses hash of serialized state.

data partitioning - although any Cache object is cluster compatible its content isn't scaled/partitioned across multiple Redis or Valkey master nodes in cluster. Data partitioning allows to scale available memory, read/write operations and entry eviction process for individual Map instance in cluster.

1. Scripted eviction

Allows to define time to live or max idle time parameters per map entry. Eviction is done on Redisson side through a custom scheduled task which removes expired entries using Lua script. Eviction task is started once per unique object name at the moment of getting Map instance. If instance isn't used and has expired entries it should be get again to start the eviction process. This leads to extra Redis or Valkey calls and eviction task per unique map object name.

Entries are cleaned time to time by org.redisson.eviction.EvictionScheduler. By default, it removes 100 expired entries at a time. This can be changed through cleanUpKeysAmount setting. Task launch time tuned automatically and depends on expired entries amount deleted in previous time and varies between 5 second to 30 minutes by default. This time interval can be changed through minCleanUpDelay and maxCleanUpDelay. For example, if clean task deletes 100 entries each time it will be executed every 5 seconds (minimum execution delay). But if current expired entries amount is lower than previous one then execution delay will be increased by 1.5 times and decreased otherwise.

Available implementations:

Setting prefix Local cache Data
partitioning
Ultra-fast
read/write
redisson.caches.*
open-source version
redisson.caches.*
Redisson PRO version
✔️
redisson.local-caches.*
available only in Redisson PRO
✔️ ✔️
redisson.clustered-caches.*
available only in Redisson PRO
✔️ ✔️
redisson.clustered-local-caches.*
available only in Redisson PRO
✔️ ✔️ ✔️

2. Advanced eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis or Valkey side.

Available implementations:

Setting prefix Local cache Data
partitioning
Ultra-fast
read/write
redisson.caches-v2.*
available only in Redisson PRO
✔️ ✔️
redisson.local-caches-v2.*
available only in Redisson PRO
✔️ ✔️ ✔️

3. Native eviction

Allows to define time to live parameter per map entry. Doesn't use an entry eviction task, entries are cleaned on Redis side.
Requires Redis 7.4+.

Available implementations:

Setting prefix Local cache Data
partitioning
Ultra-fast
read/write
redisson.caches-native.*
open-source version
redisson.caches-native.*
Redisson PRO version
✔️
redisson.local-caches-native.*
available only in Redisson PRO
✔️ ✔️
redisson.clustered-caches-native.*
available only in Redisson PRO
✔️ ✔️

Usage

1. Add redisson-micronaut dependency into your project

Maven

<dependency>
    <groupId>org.redisson</groupId>
    <!-- for Micronaut v2.0.x - v2.5.x -->
    <artifactId>redisson-micronaut-20</artifactId>
    <!-- for Micronaut v3.x.x -->
    <artifactId>redisson-micronaut-30</artifactId>
    <!-- for Micronaut v4.x.x -->
    <artifactId>redisson-micronaut-40</artifactId>
    <version>xVERSIONx</version>
</dependency>

Gradle

// for Micronaut v2.0.x - v2.5.x
compile 'org.redisson:redisson-micronaut-20:xVERSIONx'
// for Micronaut v3.x.x
compile 'org.redisson:redisson-micronaut-30:xVERSIONx'
// for Micronaut v4.x.x
compile 'org.redisson:redisson-micronaut-40:xVERSIONx'

2. Add settings into application.yml file

Config structure is a Redisson YAML configuration - (single mode, replicated mode, cluster mode, sentinel mode, proxy mode, multi cluster mode, multi sentinel mode)

NOTE: Setting names in camel case should be joined with hyphens (-).

Config example:

redisson:
  single-server-config:
     address: "redis://127.0.0.1:6379"
  threads: 16
  netty-threads: 32
  caches:
     my-cache1: 
        expire-after-write: 10s
        expire-after-access: 3s
        max-size: 1000
        codec: org.redisson.codec.Kryo5Codec
     my-cache2: 
       expire-after-write: 200s
       expire-after-access: 30s
Map Cache settings. Click to expand

Setting name: redisson.caches.[CACHE_NAME].max-size
Type: java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If 0 the cache is unbounded.
Default value: 0

Setting name: redisson.caches.[CACHE_NAME].codec
Type: java.lang.Class
Description: Data codec applied to cache entries.
Default value: org.redisson.codec.Kryo5Codec

Setting name: redisson.caches.[CACHE_NAME].expire-after-write
Type: java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.caches.[CACHE_NAME].expire-after-access
Type: java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.caches.[CACHE_NAME].write-behind-batch-size
Type: java.lang.Integer
Description: Write behind tasks batch size. During MapWriter methods execution all updates accumulated into a batch of specified size.
Default value: 50

Setting name: redisson.caches.[CACHE_NAME].write-behind-delay
Type: java.time.Duration
Description: Write behind tasks execution delay. All updates would be applied with lag not more than specified delay.
Default value: 1000ms

Setting name: redisson.caches.[CACHE_NAME].writer
Type: java.lang.Class
Description: MapWriter object used for write-through operations
Default value: null

Setting name: redisson.caches.[CACHE_NAME].write-mode
Type: java.lang.String
Description: Write mode. Default is WRITE_THROUGH
Default value: null

Setting name: redisson.caches.[CACHE_NAME].loader
Type: java.lang.Class
Description: MapLoader object used to load entries during read-operations execution
Default value: null

redisson:
  single-server-config:
    address: "redis://127.0.0.1:6379"
  clustered-caches:
    my-cache1: 
      expire-after-write: 10s
      expire-after-access: 3s
      max-size: 1000
      codec: org.redisson.codec.Kryo5Codec
    my-cache2: 
      expire-after-write: 200s
      expire-after-access: 30s
Clustered Map Cache settings. Click to expand

These settings are available only in Redisson PRO

Setting name: redisson.clustered-caches.[CACHE_NAME].max-size
Type: java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If 0 the cache is unbounded.
Default value: 0

Setting name: redisson.clustered-caches.[CACHE_NAME].codec
Type: java.lang.Class
Description: Data codec applied to cache entries.
Default value: Kryo5Codec

Setting name: redisson.clustered-caches.[CACHE_NAME].expire-after-write
Type: java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.clustered-caches.[CACHE_NAME].expire-after-access
Type: java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.clustered-caches.[CACHE_NAME].write-behind-batch-size
Type: java.lang.Integer
Description: Write behind tasks batch size. During MapWriter methods execution all updates accumulated into a batch of specified size.
Default value: 50

Setting name: redisson.clustered-caches.[CACHE_NAME].write-behind-delay
Type: java.time.Duration
Description: Write behind tasks execution delay. All updates would be applied with lag not more than specified delay.
Default value: 1000ms

Setting name: redisson.clustered-caches.[CACHE_NAME].writer
Type: java.lang.Class
Description: MapWriter object used for write-through operations
Default value: null

Setting name redisson.clustered-caches.[CACHE_NAME].write-mode
Type: java.lang.String
Description: Write mode. Default is WRITE_THROUGH
Default value: null

Setting name redisson.clustered-caches.[CACHE_NAME].loader
Type: java.lang.Class
Description: MapLoader object used to load entries during read-operations execution
Default value: null

redisson:
  single-server-config:
    address: "redis://127.0.0.1:6379"
  clustered-local-caches:
    my-cache1: 
      expire-after-write: 10s
      expire-after-access: 3s
      max-size: 1000
      codec: org.redisson.codec.Kryo5Codec
      store-сache-miss: true
      eviction-policy: `LFU`
      cache-size: 5000
      time-to-live: 2s
      max-idle: 1s
    my-cache2: 
      expire-after-write: 200s
      expire-after-access: 30s
      time-to-live: 10s
      max-idle: 5s
Clustered Local Map Cache settings. Click to expand

These settings are available only in Redisson PRO

Setting name: redisson.clustered-local-caches.[CACHE_NAME].max-size
Type: java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If 0 the cache is unbounded.
Default value: 0 |

Setting name: redisson.clustered-local-caches.[CACHE_NAME].codec
Type: java.lang.Class
Description: Data codec applied to cache entries.
Default value: Kryo5Codec

Setting name: redisson.clustered-local-caches.[CACHE_NAME].expire-after-write
Type: java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.clustered-local-caches.[CACHE_NAME].expire-after-access
Type: java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.clustered-local-caches.[CACHE_NAME].write-behind-batch-size
Type: java.lang.Integer
Description: Write behind tasks batch size. During MapWriter methods execution all updates accumulated into a batch of specified size.
Default value: 50

Setting name: redisson.clustered-local-caches.[CACHE_NAME].write-behind-delay
Type: java.time.Duration
Description: Write behind tasks execution delay. All updates would be applied with lag not more than specified delay.
Default value: 1000ms

Setting name: redisson.clustered-local-caches.[CACHE_NAME].writer
Type: java.lang.Class
Description: MapWriter object used for write-through operations
Default value: null

Setting name: redisson.clustered-local-caches.[CACHE_NAME].write-mode
Type: java.lang.String
Description: Write mode. Default is WRITE_THROUGH
Default value: null

Setting name: redisson.clustered-local-caches.[CACHE_NAME].loader
Type: java.lang.Class
Description: MapLoader object used to load entries during read-operations execution
Default value: null

Setting name: redisson.clustered-local-caches.[CACHE_NAME].cache-size
Type: java.lang.Integer
Description: Local cache size. If size is 0 then local cache is unbounded.
Default value: 0

Setting name: redisson.clustered-local-caches.[CACHE_NAME].reconnection-strategy
Type: java.lang.String
Description: Used to load missed updates during any connection failures to Redis. Since, local cache updates can't be executed in absence of connection to Redis:

  • CLEAR - Clear local cache if map instance has been disconnected for a while.
  • LOAD - Store invalidated entry hash in invalidation log for 10 minutes. Cache keys for stored invalidated entry hashes will be removed if LocalCachedMap instance has been disconnected less than 10 minutes or whole cache will be cleaned otherwise.
  • NONE - No reconnection handling

Default value: NONE

Setting name: redisson.clustered-local-caches.[CACHE_NAME].sync-strategy
Type: java.lang.String
Description: Used to synchronize local cache changes.

  • INVALIDATE - Invalidate cache entry across all LocalCachedMap instances on map entry change.
  • UPDATE - Insert/update cache entry across all LocalCachedMap instances on map entry change.
  • NONE - No synchronizations on map changes.

Default value: NONE

Setting name: redisson.clustered-local-caches.[CACHE_NAME].eviction-policy
Type: java.lang.String
Description: Defines local cache eviction policy.

  • LRU - uses local cache with LRU (least recently used) eviction policy.
  • LFU - uses local cache with LFU (least frequently used) eviction policy.
  • SOFT - uses local cache with soft references. The garbage collector will evict items from the local cache when the JVM is running out of memory.
  • WEAK - uses local cache with weak references. The garbage collector will evict items from the local cache when it became weakly reachable.
  • NONE - doesn't use eviction policy, but timeToLive and maxIdleTime params are still working.

Default value: NONE

Setting name: redisson.clustered-local-caches.[CACHE_NAME].time-to-live
Type: java.lang.Integer
Description: Time to live duration of each map entry in local cache. If value equals to 0 then timeout is not applied.
Default value: 0

Setting name: redisson.clustered-local-caches.[CACHE_NAME].max-idle
Type: java.lang.Integer
Description: Defines max idle time duration of each map entry in local cache. If value equals to 0 then timeout is not applied.
Default value: 0

Setting name: redisson.clustered-local-caches.[CACHE_NAME].cache-provider
Type: java.lang.String
Description: Defines Cache provider used as local cache store.

  • REDISSON - uses Redisson own implementation.
  • CAFFEINE - uses Caffeine implementation.

Default value: REDISSON

Setting name: redisson.clustered-local-caches.[CACHE_NAME].store-сache-miss
Type: java.lang.Boolean
Description: Defines whether to store a cache miss into the local cache.
Default value: false

redisson:
  single-server-config:
    address: "redis://127.0.0.1:6379"
  local-caches:
    my-cache1: 
      expire-after-write: 10s
      expire-after-access: 3s
      max-size: 1000
      codec: org.redisson.codec.Kryo5Codec
      store-сache-miss: true
      eviction-policy: `LFU`
      cache-size: 5000
      time-to-live: 1s
      max-idle: 1s
    my-cache2: 
      expire-after-write: 200s
      expire-after-access: 30s
      eviction-policy: `LFU`
      cache-size: 5000
      time-to-live: 10s
      max-idle: 5s
Local Cached Map Cache settings. Click to expand

These settings are available only in Redisson PRO

Setting name: redisson.local-caches.[CACHE_NAME].max-size
Type: java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If 0 the cache is unbounded.
Default value: 0

Setting name: redisson.local-caches.[CACHE_NAME].codec
Type: java.lang.Class
Description: Data codec applied to cache entries.
Default value: Kryo5Codec

Setting name: redisson.local-caches.[CACHE_NAME].expire-after-write
Type: java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.local-caches.[CACHE_NAME].expire-after-access
Type: java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is 0.
Default value: 0

Setting name: redisson.local-caches.[CACHE_NAME].write-behind-batch-size
Type: java.lang.Integer
Description: Write behind tasks batch size. During MapWriter methods execution all updates accumulated into a batch of specified size.
Default value: 50

Setting name: redisson.local-caches.[CACHE_NAME].write-behind-delay
Type: java.time.Duration
Description: Write behind tasks execution delay. All updates would be applied with lag not more than specified delay.
Default value: 1000ms

Setting name: redisson.local-caches.[CACHE_NAME].writer
Type: java.lang.Class
Description: MapWriter object used for write-through operations
Default value: null

Setting name: redisson.local-caches.[CACHE_NAME].write-mode
Type: java.lang.String
Description: Write mode. Default is WRITE_THROUGH
Default value: null

Setting name: redisson.local-caches.[CACHE_NAME].loader
Type: java.lang.Class
Description: MapLoader object used to load entries during read-operations execution
Default value: null

Setting name: redisson.local-caches.[CACHE_NAME].cache-size
Type: java.lang.Integer
Description: Local cache size. If size is 0 then local cache is unbounded.
Default value: 0

Setting name: redisson.local-caches.[CACHE_NAME].reconnection-strategy
Type: java.lang.String
Description: Used to load missed updates during any connection failures to Redis. Since, local cache updates can't be executed in absence of connection to Redis.
CLEAR - Clear local cache if map instance has been disconnected for a while.
LOAD - Store invalidated entry hash in invalidation log for 10 minutes.
Cache keys for stored invalidated entry hashes will be removed if LocalCachedMap instance has been disconnected less than 10 minutes or whole cache will be cleaned otherwise.
NONE - No reconnection handling Default value: NONE

Setting name: redisson.local-caches.[CACHE_NAME].sync-strategy
Type: java.lang.String
Description: Used to synchronize local cache changes.
INVALIDATE - Invalidate cache entry across all LocalCachedMap instances on map entry change.
UPDATE - Insert/update cache entry across all LocalCachedMap instances on map entry change.
NONE - No synchronizations on map changes.
Default value: NONE

Setting name: redisson.local-caches.[CACHE_NAME].eviction-policy
Type: java.lang.String
Description: Defines local cache eviction policy.
LRU - uses local cache with LRU (least recently used) eviction policy.
LFU - uses local cache with LFU (least frequently used) eviction policy.
SOFT - uses local cache with soft references. The garbage collector will evict items from the local cache when the JVM is running out of memory.
WEAK - uses local cache with weak references. The garbage collector will evict items from the local cache when it became weakly reachable.
NONE - doesn't use eviction policy, but timeToLive and maxIdleTime params are still working.
Default value: NONE

Setting name: redisson.local-caches.[CACHE_NAME].time-to-live
Type: java.time.Duration
Description: Time to live duration of each map entry in local cache. If value equals to 0 then timeout is not applied.
Default value: 0

Setting name: redisson.local-caches.[CACHE_NAME].max-idle
Type: java.time.Duration
Description: Defines max idle time duration of each map entry in local cache. If value equals to 0 then timeout is not applied.
Default value: 0

Setting name: redisson.local-caches.[CACHE_NAME].cache-provider
Type: java.lang.String
Description: Defines Cache provider used as local cache store.
REDISSON - uses Redisson own implementation.
CAFFEINE - uses Caffeine implementation.
Default value: 0

Setting name: redisson.local-caches.[CACHE_NAME].store-сache-miss
Type: java.lang.Boolean
Description: Defines whether to store a cache miss into the local cache.
Default value: false

Code example:

@Singleton 
@CacheConfig("my-cache1") 
public class CarsService {

    @Cacheable
    public List<String> listAll() {
        // ...
    }

    @CachePut(parameters = {"type"}) 
    public List<String> addCar(String type, String description) {
        // ...
    }

    @CacheInvalidate(parameters = {"type"}) 
    public void removeCar(String type, String description) {
        // ...
    }    
}