Cache API implementations
Spring Cache¶
Redisson provides various Spring Cache implementations.
Eviction, local cache and data partitioning¶
Redisson provides various Spring Cache managers 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 usehashCode()
/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
ormax 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
cacheData
partitioningUltra-fast
read/writeRedissonSpringCacheManager
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
cacheData
partitioningUltra-fast
read/writeRedissonSpringCacheV2Manager
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
cacheData
partitioningUltra-fast
read/writeRedissonSpringCacheNativeManager
open-source version❌ ❌ ❌ RedissonSpringCacheNativeManager
Redisson PRO version❌ ❌ ✔️ RedissonSpringLocalCachedCacheNativeManager
available only in Redisson PRO✔️ ❌ ✔️ RedissonClusteredSpringCacheNativeManager
available only in Redisson PRO❌ ✔️ ✔️ RedissonClusteredSpringLocalCachedCacheNativeManager
available only in Redisson PRO✔️ ✔️ ✔️
Local cache options
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 entry in local cache
.timeToLive(Duration.ofSeconds(10))
// max idle time for each entry in local cache
.maxIdle(Duration.ofSeconds(10));
// Defines how to listen expired event sent by Redis or Valkey upon this instance deletion
//
// Follow expiration policies are available:
// DONT_SUBSCRIBE - Don't subscribe on expire event
// SUBSCRIBE_WITH_KEYEVENT_PATTERN - Subscribe on expire event using `__keyevent@*:expired` pattern
// SUBSCRIBE_WITH_KEYSPACE_CHANNEL - Subscribe on expire event using `__keyspace@N__:name` channel
.expirationEventPolicy(ExpirationEventPolicy.SUBSCRIBE_WITH_KEYEVENT_PATTERN)
Usage¶
Each Spring Cache Manager 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);
// scripted eviction
return new RedissonSpringCacheManager(redissonClient, config);
// native eviction
return new RedissonSpringCacheManager(redissonClient, config);
// data partitioning + scripted eviction
return new RedissonClusteredSpringCacheManager(redissonClient, config);
// data partitioning + advanced eviction
return new RedissonSpringCacheV2Manager(redissonClient, config);
// data partitioning + native eviction
return new RedissonClusteredSpringCacheNativeManager(redissonClient, config);
// local cache + scripted eviction
return new RedissonSpringLocalCachedCacheManager(redissonClient, config);
// local cache + native eviction
return new RedissonSpringLocalCachedCacheNativeManager(redissonClient, config);
// local cache + data partitioning + native eviction
return new RedissonClusteredSpringLocalCachedCacheNativeManager(redissonClient, config);
// local cache + data partitioning + advanced eviction
return new RedissonSpringLocalCachedCacheV2Manager(redissonClient, config);
// local cache + data partitioning + scripted eviction
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 {
// scripted eviction
return new RedissonSpringCacheManager(redissonClient, "classpath:/cache-config.yaml");
// native eviction
return new RedissonSpringCacheManager(redissonClient, "classpath:/cache-config.yaml");
// data partitioning + scripted eviction
return new RedissonClusteredSpringCacheManager(redissonClient, "classpath:/cache-config.yaml");
// data partitioning + advanced eviction
return new RedissonSpringCacheV2Manager(redissonClient, "classpath:/cache-config.yaml");
// data partitioning + native eviction
return new RedissonClusteredSpringCacheNativeManager(redissonClient, "classpath:/cache-config.yaml");
// local cache + scripted eviction
return new RedissonSpringLocalCachedCacheManager(redissonClient, "classpath:/cache-config.yaml");
// local cache + native eviction
return new RedissonSpringLocalCachedCacheNativeManager(redissonClient, "classpath:/cache-config.yaml");
// local cache + data partitioning + native eviction
return new RedissonClusteredSpringLocalCachedCacheNativeManager(redissonClient, "classpath:/cache-config.yaml");
// local cache + data partitioning + advanced eviction
return new RedissonSpringLocalCachedCacheV2Manager(redissonClient, "classpath:/cache-config.yaml");
// local cache + data partitioning + scripted eviction
return new RedissonClusteredSpringLocalCachedCacheManager(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
Note
localCacheOptions
settings are available for RedissonSpringLocalCachedCacheManager
, RedissonClusteredSpringLocalCachedCacheManager
, RedissonSpringLocalCachedCacheV2Manager
, RedissonSpringLocalCachedCacheNativeManager
, RedissonClusteredSpringLocalCachedCacheNativeManager
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 usehashCode()
/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.
-
Scripted eviction
Allows to define
time to live
ormax idle time
parameters per map entry. Eviction is executed by Redisson through a custom scheduled task which removes expired entries using Lua script on Redis or Valkey side. 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
partitioningUltra-fast
read/writeRedissonRegionFactory
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✔️ ✔️ ✔️ -
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
partitioningUltra-fast
read/writeRedissonRegionV2Factory
available only in Redisson PRO❌ ✔️ ✔️ RedissonLocalCachedV2RegionFactory
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 or Valkey side.
Requires Redis 7.4+.Available implementations:
Class name Local cache Data
partitioningUltra-fast
read/writeRedissonRegionNativeFactory
open-source version❌ ❌ ❌ RedissonRegionNativeFactory
Redisson PRO version❌ ❌ ✔️ RedissonLocalCachedNativeRegionFactory
available only in Redisson PRO✔️ ❌ ✔️ RedissonClusteredNativeRegionFactory
available only in Redisson PRO❌ ✔️ ✔️ RedissonClusteredLocalCachedNativeRegionFactory
available only in Redisson PRO✔️ ✔️ ✔️
Usage¶
-
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.44.0</version> </dependency>
Gradle
// for Hibernate v4.x compile 'org.redisson:redisson-hibernate-4:3.44.0' // for Hibernate v5.0.x - v5.1.x compile 'org.redisson:redisson-hibernate-5:3.44.0' // for Hibernate v5.2.x compile 'org.redisson:redisson-hibernate-52:3.44.0' // for Hibernate v5.3.3+ - v5.6.x compile 'org.redisson:redisson-hibernate-53:3.44.0' // for Hibernate v6.0.2+ - v6.x.x compile 'org.redisson:redisson-hibernate-6:3.44.0'
-
Specify hibernate cache settings
<!-- 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" />
Define Redisson Region Cache Factory in
hibernate.cfg.xml
file:<!-- Scripted Eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonRegionFactory" /> <!-- Native Eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonRegionNativeFactory" /> <!-- Data partitioning + Advanced eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonRegionV2Factory" /> <!-- Local cache + Scripted eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonLocalCachedRegionFactory" /> <!-- Local cache + Data partitioning + Advanced eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonLocalCachedV2RegionFactory" /> <!-- Local cache + Native Eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonLocalCachedNativeRegionFactory" /> <!-- Data partitioning + Scripted eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonClusteredRegionFactory" /> <!-- Data partitioning + Native eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonClusteredNativeRegionFactory" /> <!-- Local cache + Data partitioning + Scripted eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonClusteredLocalCachedRegionFactory" /> <!-- Local cache + Data partitioning + Native eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonClusteredLocalCachedNativeRegionFactory" />
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" /> <!-- Scripted Eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonRegionFactory" /> <!-- Native Eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonRegionNativeFactory" /> <!-- Data partitioning + Advanced eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonRegionV2Factory" /> <!-- Local cache + Scripted eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonLocalCachedRegionFactory" /> <!-- Local cache + Data partitioning + Advanced eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonLocalCachedV2RegionFactory" /> <!-- Local cache + Native Eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonLocalCachedNativeRegionFactory" /> <!-- Data partitioning + Scripted eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonClusteredRegionFactory" /> <!-- Data partitioning + Native eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonClusteredNativeRegionFactory" /> <!-- Local cache + Data partitioning + Scripted eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonClusteredLocalCachedRegionFactory" /> <!-- Local cache + Data partitioning + Native eviction --> <property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.JndiRedissonClusteredLocalCachedNativeRegionFactory" />
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.
Property name: 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
Property name: 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
Property name: 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
Property name: 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
Property name: hibernate.cache.redisson.[REGION_NAME].localcache.store_mode
Description: Store mode of cache data. 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.
Default value: LOCALCACHE
Property name: 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
Property name: 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
Property name: 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
Property name: hibernate.cache.redisson.[REGION_NAME].localcache.sync_strategy
Description: Sync strategy used to synchronize local cache changes across all instances. Available values:
INVALIDATE
- Invalidate cache entry across all LocalCachedMap instances on map entry changeUPDATE
- Update cache entry across all LocalCachedMap instances on map entry changeNONE
- No synchronizations on map changes
Default value: INVALIDATE
Property name: hibernate.cache.redisson.[REGION_NAME].localcache.reconnection_strategy
Description: Reconnection strategy is used to load missed local cache updates through Hibernate during any connection failures to Redis. Available values:
CLEAR
- Clear local cache if map instance has been disconnected for a whileLOAD
- 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 otherwiseNONE
- No reconnection handling
Default value: NONE
Property name: 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
, RedissonLocalCachedV2RegionFactory
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.
Provided implementation fully passes TCK tests. Here is the test module.
Eviction, local cache and data partitioning¶
Redisson provides JCache implementations with many 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. -
Scripted eviction
Eviction is executed by Redisson through a custom scheduled task which removes expired entries using Lua script on Redis or Valkey side. Eviction task is started once per unique cache name at the moment of getting JCache 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 cache 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:
Local
cacheData
partitioningUltra-fast
read/writeFallback
modeJCache
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✔️ ✔️ ✔️ ✔️ -
Advanced eviction
Doesn't use an entry eviction task, entries are cleaned on Redis or Valkey side.
Available implementations:
Local
cacheData
partitioningUltra-fast
read/writeFallback
modeJCache V2
available only in Redisson PRO❌ ✔️ ✔️ ✔️ JCache V2 with local cache
available only in Redisson PRO✔️ ✔️ ✔️ ✔️ -
Native eviction
Doesn't use an entry eviction task, entries are cleaned on Redis side.
Requires Redis 7.4+.Available implementations:
Local
cacheData
partitioningUltra-fast
read/writeFallback
modeJCache native
available only in Redisson PRO❌ ❌ ✔️ ✔️ JCache native with data partitioning
available only in Redisson PRO❌ ✔️ ✔️ ✔️ JCache native with local cache and data partitioning
available only in Redisson PRO✔️ ✔️ ✔️ ✔️
Usage¶
Below are the examples of JCache API usage.
-
Using default config located at
/redisson-jcache.yaml
:// implementation with scripted eviction MutableConfiguration<String, String> config = new MutableConfiguration<>(); // implementation with native eviction NativeConfiguration<String, String> config = new NativeConfiguration<>(); // implementation with advanced eviction V2Configuration<String, String> config = new V2Configuration<>(); CacheManager manager = Caching.getCachingProvider().getCacheManager(); Cache<String, String> cache = manager.createCache("namedCache", config);
-
Using config file with custom location:
// implementation with scripted eviction MutableConfiguration<String, String> config = new MutableConfiguration<>(); // implementation with native eviction NativeConfiguration<String, String> config = new NativeConfiguration<>(); // implementation with advanced eviction V2Configuration<String, String> config = new V2Configuration<>(); // 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);
-
Using Redisson's config object:
// implementation with scripted eviction MutableConfiguration<String, String> jcacheConfig = new MutableConfiguration<>(); // implementation with native eviction NativeConfiguration<String, String> jcacheConfig = new NativeConfiguration<>(); // implementation with advanced eviction V2Configuration<String, String> jcacheConfig = new V2Configuration<>(); Config redissonCfg = ... Configuration<String, String> config = RedissonConfiguration.fromConfig(redissonCfg, jcacheConfig); CacheManager manager = Caching.getCachingProvider().getCacheManager(); Cache<String, String> cache = manager.createCache("namedCache", config);
-
Using Redisson instance object:
// implementation with scripted eviction MutableConfiguration<String, String> jcacheConfig = new MutableConfiguration<>(); // implementation with native eviction NativeConfiguration<String, String> jcacheConfig = new NativeConfiguration<>(); // implementation with advanced eviction V2Configuration<String, String> jcacheConfig = new V2Configuration<>(); 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.
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 entry in local cache
.timeToLive(Duration.ofSeconds(10))
// max idle time for each entry in local cache
.maxIdle(Duration.ofSeconds(10));
// Defines how to listen expired event sent by Redis or Valkey upon this instance deletion
//
// Follow expiration policies are available:
// DONT_SUBSCRIBE - Don't subscribe on expire event
// SUBSCRIBE_WITH_KEYEVENT_PATTERN - Subscribe on expire event using `__keyevent@*:expired` pattern
// SUBSCRIBE_WITH_KEYSPACE_CHANNEL - Subscribe on expire event using `__keyspace@N__:name` channel
.expirationEventPolicy(ExpirationEventPolicy.SUBSCRIBE_WITH_KEYEVENT_PATTERN)
Usage example:
// implementation with local cache + scripted eviction
LocalCacheConfiguration<String, String> config = new LocalCacheConfiguration<>();
.setEvictionPolicy(EvictionPolicy.LFU)
.setTimeToLive(48, TimeUnit.MINUTES)
.setMaxIdle(24, TimeUnit.MINUTES)
.setCacheSize(1000);
// implementation with local cache + native eviction
LocalCacheNativeConfiguration<String, String> config = new LocalCacheNativeConfiguration<>();
.setEvictionPolicy(EvictionPolicy.LFU)
.setTimeToLive(48, TimeUnit.MINUTES)
.setMaxIdle(24, TimeUnit.MINUTES)
.setCacheSize(1000);
// implementation with local cache + advanced eviction
LocalCacheV2Configuration<String, String> config = new LocalCacheV2Configuration<>();
.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:
// implementation with data partitioning + scripted eviction
ClusteredConfiguration<String, String> config = new ClusteredConfiguration<>();
// implementation with data partitioning + native eviction
ClusteredNativeConfiguration<String, String> config = new ClusteredNativeConfiguration<>();
// implementation with data partitioning + advanced eviction
V2Configuration<String, String> config = new V2Configuration<>();
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 entry in local cache
.timeToLive(Duration.ofSeconds(10))
// max idle time for each entry in local cache
.maxIdle(Duration.ofSeconds(10));
// Defines how to listen expired event sent by Redis or Valkey upon this instance deletion
//
// Follow expiration policies are available:
// DONT_SUBSCRIBE - Don't subscribe on expire event
// SUBSCRIBE_WITH_KEYEVENT_PATTERN - Subscribe on expire event using `__keyevent@*:expired` pattern
// SUBSCRIBE_WITH_KEYSPACE_CHANNEL - Subscribe on expire event using `__keyspace@N__:name` channel
.expirationEventPolicy(ExpirationEventPolicy.SUBSCRIBE_WITH_KEYEVENT_PATTERN)
Usage examples:
// implementation with data partitioning + local cache + scripted eviction
ClusteredLocalCacheConfiguration<String, String> config = new ClusteredLocalCacheConfiguration<>();
config.cacheSize(1000);
config.timeToLive(Duration.ofSeconds(10));
// implementation with data partitioning + local cache + native eviction
ClusteredLocalCacheNativeConfiguration<String, String> config = new ClusteredLocalCacheNativeConfiguration<>();
config.cacheSize(1000);
config.timeToLive(Duration.ofSeconds(10));
// implementation with data partitioning + local cache + advanced eviction
LocalCacheV2Configuration<String, String> config = new LocalCacheV2Configuration<>();
config.cacheSize(1000);
config.timeToLive(Duration.ofSeconds(10));
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);
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:
// implementation with scripted eviction
MutableConfiguration<String, String> config = new MutableConfiguration<>();
// implementation with native eviction
NativeConfiguration<String, String> config = new NativeConfiguration<>();
// implementation with advanced eviction
V2Configuration<String, String> config = new V2Configuration<>();
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:
// implementation with scripted eviction
MutableConfiguration<String, String> config = new MutableConfiguration<>();
// implementation with native eviction
NativeConfiguration<String, String> config = new NativeConfiguration<>();
// implementation with advanced eviction
V2Configuration<String, String> config = new V2Configuration<>();
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:
// implementation with scripted eviction
MutableConfiguration<String, String> config = new MutableConfiguration<>();
// implementation with native eviction
NativeConfiguration<String, String> config = new NativeConfiguration<>();
// implementation with advanced eviction
V2Configuration<String, String> config = new V2Configuration<>();
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");
Open Liberty or WebSphere Liberty integration¶
Distributed Cache configuration example:
<library id="jCacheVendorLib">
<file name="${shared.resource.dir}/redisson-all-3.43.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.43.0.jar"/>
</library>
<httpSessionCache cacheManagerRef="CacheManager"/>
<cacheManager id="CacheManager" uri="file:${server.config.dir}/redisson-jcache.yaml">
<properties fallback="true"/>
<cachingProvider jCacheLibraryRef="jCacheVendorLib"/>
</cacheManager>
JCache settings
Settings are available only in Redisson PRO edition.
-
fallback
Default value:
false
Description: Skip errors if Redis or Valkey cache is unavailable. -
implementation
Default value:
cache
Description: Cache implementation. Available values:cache
- implementation with scripted evictionlocal-cache
- implementation with local cache and scripted evictionclustered-cache
- implementation with data partitioning and scripted eviction-
clustered-local-cache
- implementation with data partitioning, local cache support and scripted eviction -
cache-v2
- implementation with data partitioning and advanced eviction -
local-cache-v2
- implementation with local cache, data partitioning and advanced eviction -
native-cache
- implementation with native eviction local-cache-native
- implementation with local cache and native evictionclustered-native-cache
- implementation with data partitioning and native evictionclustered-local-cache-native
- implementation with data partitioning, local cache support and native eviction
-
localcache.store_cache_miss
Default value:
false
Description: Defines whether to store a cache miss into the local cache. -
localcache.cache_provider
Default value:
REDISSON
Description: Defines a cache provider used as local cache store. Available values:REDISSON
CAFFEINE
-
localcache.store_mode
Default value:
LOCALCACHE
Description: Store mode of cache data. Available values:LOCALCACHE
- store data in local cache only and use Redis or Valkey only for data update/invalidationLOCALCACHE_REDIS
- store data in both Redis or Valkey and local cache
-
localcache.max_idle_time
Default value:
0
Description: Max idle time per entry in local cache. Defined in milliseconds.0
value means this setting doesn't affect expiration. -
localcache.time_to_live
Default value:
0
Description: Time to live per entry in local cache. Defined in milliseconds.0
value means this setting doesn't affect expiration. -
localcache.eviction_policy
Default value:
NONE
Description: Eviction policy applied to local cache entries when cache size limit reached. Available values:LFU
- Counts how often an item was requested. Those that are used least often are discarded first.LRU
- Discards the least recently used items firstSOFT
- Uses weak references, entries are removed by GCWEAK
- Uses soft references, entries are removed by GCNONE
- No eviction
-
localcache.sync_strategy
Default value:
INVALIDATE
Description: Sync strategy used to synchronize local cache changes across all instances. Available values:INVALIDATE
- Invalidate cache entry across all LocalCachedMap instances on map entry changeUPDATE
- Update cache entry across all LocalCachedMap instances on map entry changeNONE
- No synchronizations on map changes |
-
localcache.reconnection_strategy
Default value:
NONE
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 whileLOAD
- 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 otherwiseNONE
- No reconnection handling
-
localcache.size
Default value:
0
Description: Max size of local cache. Superfluous entries in Redis or Valkey are evicted using defined eviction policy.0
value means unbounded cache.
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 usehashCode()
/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.
-
Scripted eviction
Allows to define
time to live
ormax idle time
parameters per entry. Eviction is executed by Redisson through a custom scheduled task which removes expired entries using Lua script on Redis or Valkey side. 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
cacheData
partitioningUltra-fast
read/writeRedissonCache
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✔️ ✔️ ✔️ -
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
cacheData
partitioningUltra-fast
read/writeRedissonCacheV2
available only in Redisson PRO❌ ✔️ ✔️ RedissonLocalCachedCacheV2
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
cacheData
partitioningUltra-fast
read/writeRedissonCacheNative
open-source version❌ ❌ ❌ RedissonCacheNative
Redisson PRO version❌ ❌ ✔️ RedissonLocalCachedCacheNative
available only in Redisson PRO✔️ ❌ ✔️ RedissonClusteredCacheNative
available only in Redisson PRO❌ ✔️ ✔️ RedissonClusteredLocalCachedCacheNative
available only in Redisson PRO✔️ ✔️ ✔️
Usage¶
-
Add
redisson-mybatis
dependency into your projectMaven
<dependency> <groupId>org.redisson</groupId> <artifactId>redisson-mybatis</artifactId> <version>3.44.0</version> </dependency>
Gradle
-
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 or Valkey
-
localCacheProvider
Cache provider used as local cache store.
REDISSON
andCAFFEINE
providers are available. Default value:REDISSON
-
localCacheEvictionPolicy
Local cache eviction policy.
LFU
,LRU
,SOFT
,WEAK
andNONE
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
andNONE
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 usehashCode()
/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
ormax idle time
parameters per map entry. Eviction is executed by Redisson through a custom scheduled task which removes expired entries using Lua script on Redis or Valkey side. 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 valueLocal
cacheData
partitioningUltra-fast
read/writestandard
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✔️ ✔️ ✔️ -
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 valueLocal
cacheData
partitioningUltra-fast
read/writev2
available only in Redisson PRO❌ ✔️ ✔️ localcache_v2
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:
impementation
setting valueLocal
cacheData
partitioningUltra-fast
read/writenative
open-source version❌ ❌ ❌ native
Redisson PRO version❌ ❌ ✔️ localcache_native
available only in Redisson PRO✔️ ❌ ✔️ clustered_native
available only in Redisson PRO❌ ✔️ ✔️ clustered_localcache_native
available only in Redisson PRO✔️ ✔️ ✔️
Usage¶
-
Add
redisson-quarkus-cache
dependency into your projectMaven
<dependency> <groupId>org.redisson</groupId> <!-- for Quarkus v3.x.x --> <artifactId>redisson-quarkus-30-cache</artifactId> <version>3.44.0</version> </dependency>
Gradle
-
Add settings into
application.properties
file-
Basic settings
-
max-size
Setting defines maximum size of this cache. Superfluous elements are evicted using LRU algorithm. If
0
the cache is unbounded. Default value is0
. -
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
. Availabile values:standard
- implementation with scripted evictionv2
- implementation with data partitioning and advanced evictionnative
- implementation with native evictionclustered_native
- implementation with data partitioning and native evictionlocalcache
- implementation with local cache and scripted evictionlocalcache_v2
- implementation with local cache, data partitioning and advanced evictionlocalcache_native
- implementation with local cache and native evictionclustered_localcache
- implementation with data partitioning, local cache and scripted evictionclustered
- implementation with data partitioning and scripted evictionclustered_localcache_native
- implementation with data partitioning, local cache and native eviction
Below is the cache configuration example.
quarkus.cache.type=redisson quarkus.cache.redisson.implementation=standard # Default configuration for all caches quarkus.cache.redisson.max-size=10000 quarkus.cache.redisson.expire-after-write=5s quarkus.cache.redisson.expire-after-access=1s # Configuration for `sampleCache` cache quarkus.cache.redisson.sampleCache.max-size=1000 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 is
CLEAR
. 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
-
quarkus.cache.redisson.[CACHE_NAME].sync-strategy
Used to synchronize local cache changes. Default value is
INVALIDATE
. 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.
-
quarkus.cache.redisson.[CACHE_NAME].eviction-policy
Defines local cache eviction policy. Default value is
NONE
. 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.
-
quarkus.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
. -
quarkus.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/invalidationLOCALCACHE_REDIS
- store data in both Redis or Valkey and local cache
-
quarkus.cache.redisson.[CACHE_NAME].cache-provider
Defines Cache provider used as local cache store. Default value is
REDISSON
. Available values:REDISSON
- uses Redisson own implementationCAFFEINE
- uses Caffeine implementation
-
quarkus.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.max-size=1000
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 usehashCode()
/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.
-
Scripted eviction
Allows to define
time to live
ormax 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
partitioningUltra-fast
read/writeredisson.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✔️ ✔️ ✔️ -
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
partitioningUltra-fast
read/writeredisson.caches-v2.*
available only in Redisson PRO❌ ✔️ ✔️ redisson.local-caches-v2.*
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:
Setting prefix Local cache Data
partitioningUltra-fast
read/writeredisson.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❌ ✔️ ✔️ redisson.clustered-local-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:
-
Scripted eviction
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. If0
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 is0
.
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 is0
.
Default value:0
Setting name:
redisson.caches.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
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 isWRITE_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
-
Data partitioning + Scripted eviction
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. If0
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 is0
.
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 is0
.
Default value:0
Setting name:
redisson.clustered-caches.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
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 isWRITE_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
-
Local cache + Data partitioning + Scripted eviction
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. If0
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 is0
.
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 is0
.
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. DuringMapWriter
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 isWRITE_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 is0
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 to0
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 to0
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
-
Local cache + Scripted eviction
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. If0
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 is0
.
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 is0
.
Default value:0
Setting name:
redisson.local-caches.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
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 isWRITE_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 is0
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 to0
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 to0
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
-
Native eviction
redisson: single-server-config: address: "redis://127.0.0.1:6379" threads: 16 netty-threads: 32 caches-native: 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 Native settings. Click to expand
Setting name:
redisson.caches-native.[CACHE_NAME].max-size
Type:java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If0
the cache is unbounded.
Default value:0
Setting name:
redisson.caches-native.[CACHE_NAME].codec
Type:java.lang.Class
Description: Data codec applied to cache entries.
Default value:org.redisson.codec.Kryo5Codec
Setting name:
redisson.caches-native.[CACHE_NAME].expire-after-write
Type:java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.caches-native.[CACHE_NAME].expire-after-access
Type:java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.caches-native.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
methods execution all updates accumulated into a batch of specified size.
Default value:50
Setting name:
redisson.caches-native.[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-native.[CACHE_NAME].writer
Type:java.lang.Class
Description:MapWriter
object used for write-through operations
Default value:null
Setting name:
redisson.caches-native.[CACHE_NAME].write-mode
Type:java.lang.String
Description: Write mode. Default isWRITE_THROUGH
Default value:null
Setting name:
redisson.caches-native.[CACHE_NAME].loader
Type:java.lang.Class
Description:MapLoader
object used to load entries during read-operations execution
Default value:null
-
Data partitioning + Native eviction
redisson: single-server-config: address: "redis://127.0.0.1:6379" clustered-caches-native: 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 Native settings. Click to expand
These settings are available only in Redisson PRO
Setting name:
redisson.clustered-caches-native.[CACHE_NAME].max-size
Type:java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If0
the cache is unbounded.
Default value:0
Setting name:
redisson.clustered-caches-native.[CACHE_NAME].codec
Type:java.lang.Class
Description: Data codec applied to cache entries.
Default value:Kryo5Codec
Setting name:
redisson.clustered-caches-native.[CACHE_NAME].expire-after-write
Type:java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.clustered-caches-native.[CACHE_NAME].expire-after-access
Type:java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.clustered-caches-native.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
methods execution all updates accumulated into a batch of specified size.
Default value:50
Setting name:
redisson.clustered-caches-native.[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-native.[CACHE_NAME].writer
Type:java.lang.Class
Description:MapWriter
object used for write-through operations
Default value:null
Setting name
redisson.clustered-caches-native.[CACHE_NAME].write-mode
Type:java.lang.String
Description: Write mode. Default isWRITE_THROUGH
Default value:null
Setting name
redisson.clustered-caches-native.[CACHE_NAME].loader
Type:java.lang.Class
Description:MapLoader
object used to load entries during read-operations execution
Default value:null
-
Local cache + Data partitioning + Scripted eviction
redisson: single-server-config: address: "redis://127.0.0.1:6379" clustered-local-caches-native: 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 Native settings. Click to expand
These settings are available only in Redisson PRO
Setting name:
redisson.clustered-local-caches-native.[CACHE_NAME].max-size
Type:java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If0
the cache is unbounded.
Default value:0
|Setting name:
redisson.clustered-local-caches-native.[CACHE_NAME].codec
Type:java.lang.Class
Description: Data codec applied to cache entries.
Default value:Kryo5Codec
Setting name:
redisson.clustered-local-caches-native.[CACHE_NAME].expire-after-write
Type:java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.clustered-local-caches-native.[CACHE_NAME].expire-after-access
Type:java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.clustered-local-caches-native.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
methods execution all updates accumulated into a batch of specified size.
Default value:50
Setting name:
redisson.clustered-local-caches-native.[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-native.[CACHE_NAME].writer
Type:java.lang.Class
Description:MapWriter
object used for write-through operations
Default value:null
Setting name:
redisson.clustered-local-caches-native.[CACHE_NAME].write-mode
Type:java.lang.String
Description: Write mode. Default isWRITE_THROUGH
Default value:null
Setting name:
redisson.clustered-local-caches-native.[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-native.[CACHE_NAME].cache-size
Type:java.lang.Integer
Description: Local cache size. If size is0
then local cache is unbounded.
Default value:0
Setting name:
redisson.clustered-local-caches-native.[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-native.[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-native.[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-native.[CACHE_NAME].time-to-live
Type:java.lang.Integer
Description: Time to live duration of each map entry in local cache. If value equals to0
then timeout is not applied.
Default value:0
Setting name:
redisson.clustered-local-caches-native.[CACHE_NAME].max-idle
Type:java.lang.Integer
Description: Defines max idle time duration of each map entry in local cache. If value equals to0
then timeout is not applied.
Default value:0
Setting name:
redisson.clustered-local-caches-native.[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-native.[CACHE_NAME].store-сache-miss
Type:java.lang.Boolean
Description: Defines whether to store a cache miss into the local cache.
Default value:false
-
Local cache + Native eviction
redisson: single-server-config: address: "redis://127.0.0.1:6379" local-caches-native: 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 Native settings. Click to expand
These settings are available only in Redisson PRO
Setting name:
redisson.local-caches-native.[CACHE_NAME].max-size
Type:java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If0
the cache is unbounded.
Default value:0
Setting name:
redisson.local-caches-native.[CACHE_NAME].codec
Type:java.lang.Class
Description: Data codec applied to cache entries.
Default value:Kryo5Codec
Setting name:
redisson.local-caches-native.[CACHE_NAME].expire-after-write
Type:java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.local-caches-native.[CACHE_NAME].expire-after-access
Type:java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.local-caches-native.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
methods execution all updates accumulated into a batch of specified size.
Default value:50
Setting name:
redisson.local-caches-native.[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-native.[CACHE_NAME].writer
Type:java.lang.Class
Description:MapWriter
object used for write-through operations
Default value:null
Setting name:
redisson.local-caches-native.[CACHE_NAME].write-mode
Type:java.lang.String
Description: Write mode. Default isWRITE_THROUGH
Default value:null
Setting name:
redisson.local-caches-native.[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-native.[CACHE_NAME].cache-size
Type:java.lang.Integer
Description: Local cache size. If size is0
then local cache is unbounded.
Default value:0
Setting name:
redisson.local-caches-native.[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-native.[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-native.[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-native.[CACHE_NAME].time-to-live
Type:java.time.Duration
Description: Time to live duration of each map entry in local cache. If value equals to0
then timeout is not applied.
Default value:0
Setting name:
redisson.local-caches-native.[CACHE_NAME].max-idle
Type:java.time.Duration
Description: Defines max idle time duration of each map entry in local cache. If value equals to0
then timeout is not applied.
Default value:0
Setting name:
redisson.local-caches-native.[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-native.[CACHE_NAME].store-сache-miss
Type:java.lang.Boolean
Description: Defines whether to store a cache miss into the local cache.
Default value:false
-
Data partitioning + Advanced eviction
redisson: single-server-config: address: "redis://127.0.0.1:6379" threads: 16 netty-threads: 32 caches-v2: 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 V2 settings. Click to expand
Setting name:
redisson.caches-v2.[CACHE_NAME].max-size
Type:java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If0
the cache is unbounded.
Default value:0
Setting name:
redisson.caches-v2.[CACHE_NAME].codec
Type:java.lang.Class
Description: Data codec applied to cache entries.
Default value:org.redisson.codec.Kryo5Codec
Setting name:
redisson.caches-v2.[CACHE_NAME].expire-after-write
Type:java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.caches-v2.[CACHE_NAME].expire-after-access
Type:java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.caches-v2.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
methods execution all updates accumulated into a batch of specified size.
Default value:50
Setting name:
redisson.caches-v2.[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-v2.[CACHE_NAME].writer
Type:java.lang.Class
Description:MapWriter
object used for write-through operations
Default value:null
Setting name:
redisson.caches-v2.[CACHE_NAME].write-mode
Type:java.lang.String
Description: Write mode. Default isWRITE_THROUGH
Default value:null
Setting name:
redisson.caches-v2.[CACHE_NAME].loader
Type:java.lang.Class
Description:MapLoader
object used to load entries during read-operations execution
Default value:null
-
Local cache + Data partitioning + Advanced eviction
redisson: single-server-config: address: "redis://127.0.0.1:6379" local-caches-v2: 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
Local Map Cache V2 settings. Click to expand
These settings are available only in Redisson PRO
Setting name:
redisson.local-caches-v2.[CACHE_NAME].max-size
Type:java.lang.Integer
Description: Max size of this cache. Superfluous elements are evicted using LRU algorithm. If0
the cache is unbounded.
Default value:0
|Setting name:
redisson.local-caches-v2.[CACHE_NAME].codec
Type:java.lang.Class
Description: Data codec applied to cache entries.
Default value:Kryo5Codec
Setting name:
redisson.local-caches-v2.[CACHE_NAME].expire-after-write
Type:java.time.Duration
Description: Cache entry time to live duration applied after each write operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.local-caches-v2.[CACHE_NAME].expire-after-access
Type:java.time.Duration
Description: Cache entry time to live duration applied after each read operation. Disabled if value is0
.
Default value:0
Setting name:
redisson.local-caches-v2.[CACHE_NAME].write-behind-batch-size
Type:java.lang.Integer
Description: Write behind tasks batch size. DuringMapWriter
methods execution all updates accumulated into a batch of specified size.
Default value:50
Setting name:
redisson.local-caches-v2.[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-v2.[CACHE_NAME].writer
Type:java.lang.Class
Description:MapWriter
object used for write-through operations
Default value:null
Setting name:
redisson.local-caches-v2.[CACHE_NAME].write-mode
Type:java.lang.String
Description: Write mode. Default isWRITE_THROUGH
Default value:null
Setting name:
redisson.local-caches-v2.[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-v2.[CACHE_NAME].cache-size
Type:java.lang.Integer
Description: Local cache size. If size is0
then local cache is unbounded.
Default value:0
Setting name:
redisson.local-caches-v2.[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-v2.[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-v2.[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-v2.[CACHE_NAME].time-to-live
Type:java.lang.Integer
Description: Time to live duration of each map entry in local cache. If value equals to0
then timeout is not applied.
Default value:0
Setting name:
redisson.local-caches-v2.[CACHE_NAME].max-idle
Type:java.lang.Integer
Description: Defines max idle time duration of each map entry in local cache. If value equals to0
then timeout is not applied.
Default value:0
Setting name:
redisson.local-caches-v2.[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.local-caches-v2.[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) {
// ...
}
}