Class RedissonCacheNative<K,V>

java.lang.Object
com.axelor.cache.redisson.AbstractRedissonCache<K,V,org.redisson.api.RMapCacheNative<K,V>>
com.axelor.cache.redisson.RedissonCacheNative<K,V>
Type Parameters:
K - the type of keys maintained by this cache
V - the type of mapped values
All Implemented Interfaces:
AxelorCache<K,V>, Closeable, AutoCloseable, Iterable<Map.Entry<K,V>>
Direct Known Subclasses:
RedissonLoadingCacheNative

public class RedissonCacheNative<K,V> extends AbstractRedissonCache<K,V,org.redisson.api.RMapCacheNative<K,V>>
Redisson cache with native eviction

This implementation wraps a RMapCacheNative and relies on Redis capabilities for handling entry expiration.

Important Note on Redis Version:
Setting Time-To-Live (TTL) requires the HPEXPIRE command, which was introduced in Redis 7.4. Ensure your Redis server version is compatible.

Limitations compared to standard RMapCache:

  • Expire After Access: Not natively supported. This implementation falls back to expireAfterWrite (TTL) and logs a warning.
  • Maximum Size: Not natively supported. This implementation falls back to a default TTL (1 hour) if no other TTL is set, and logs a warning.
  • Constructor Details

    • RedissonCacheNative

      public RedissonCacheNative(org.redisson.api.RMapCacheNative<K,V> cache)
  • Method Details

    • setExpireAfterWrite

      public void setExpireAfterWrite(Duration expireAfterWrite)
      Specified by:
      setExpireAfterWrite in class AbstractRedissonCache<K,V,org.redisson.api.RMapCacheNative<K,V>>
    • setExpireAfterAccess

      public void setExpireAfterAccess(Duration expireAfterAccess)
      Specified by:
      setExpireAfterAccess in class AbstractRedissonCache<K,V,org.redisson.api.RMapCacheNative<K,V>>
    • setMaximumSize

      public void setMaximumSize(int maximumSize)
      Specified by:
      setMaximumSize in class AbstractRedissonCache<K,V,org.redisson.api.RMapCacheNative<K,V>>
    • get

      public V get(K key, Function<? super K,? extends V> mappingFunction)
      Description copied from interface: AxelorCache
      Returns the value associated with the key in this cache, obtaining that value from the mappingFunction if necessary.
      Parameters:
      key - the key with which the specified value is to be associated
      mappingFunction - the function to compute a value
      Returns:
      the current (existing or computed) value associated with the specified key, or null if the computed value is null
    • put

      public void put(K key, V value)
      Description copied from interface: AxelorCache
      Associates the value with the key.
      Specified by:
      put in interface AxelorCache<K,V>
      Overrides:
      put in class AbstractRedissonCache<K,V,org.redisson.api.RMapCacheNative<K,V>>
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
    • putAll

      public void putAll(Map<? extends K,? extends V> map)
      Description copied from interface: AxelorCache
      Copies all of the mappings from the specified map to the cache.

      The effect of this call is equivalent to that of calling put(key, value) on this map once for each mapping from key to value in the specified map.

      Specified by:
      putAll in interface AxelorCache<K,V>
      Overrides:
      putAll in class AbstractRedissonCache<K,V,org.redisson.api.RMapCacheNative<K,V>>
      Parameters:
      map - the mappings to be stored in this cache