Class AbstractRedissonCache<K,V,M extends org.redisson.api.RMap<K,V>>

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

public abstract class AbstractRedissonCache<K,V,M extends org.redisson.api.RMap<K,V>> extends Object implements AxelorCache<K,V>
Redisson cache with configurability of cache eviction policies.
  • Field Details

    • cache

      protected final M extends org.redisson.api.RMap<K,V> cache
  • Constructor Details

    • AbstractRedissonCache

      protected AbstractRedissonCache(M cache)
  • Method Details

    • setExpireAfterWrite

      public abstract void setExpireAfterWrite(Duration expireAfterWrite)
    • setExpireAfterAccess

      public abstract void setExpireAfterAccess(Duration expireAfterAccess)
    • setMaximumSize

      public abstract void setMaximumSize(int maximumSize)
    • get

      public V get(K key)
      Description copied from interface: AxelorCache
      Returns the value associated with the key in this cache, obtaining that value from the CacheLoader if defined and if necessary, otherwise returns null if there is no cached value for the key.
      Specified by:
      get in interface AxelorCache<K,V>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
    • getAll

      public Map<K,V> getAll(Set<K> keys)
      Description copied from interface: AxelorCache
      Returns a map of the values associated with the keys in this cache, using CacheLoader if defined and if necessary.
      Specified by:
      getAll in interface AxelorCache<K,V>
      Parameters:
      keys - the keys whose associated values are to be returned
      Returns:
      an unmodifiable mapping of keys to values for the specified keys in this cache
    • 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>
      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>
      Parameters:
      map - the mappings to be stored in this cache
    • invalidate

      public void invalidate(K key)
      Description copied from interface: AxelorCache
      Discards any cached value for the key.
      Specified by:
      invalidate in interface AxelorCache<K,V>
      Parameters:
      key - the key whose mapping is to be removed from the cache
    • invalidateAll

      public void invalidateAll()
      Description copied from interface: AxelorCache
      Discards all cached values.
      Specified by:
      invalidateAll in interface AxelorCache<K,V>
    • close

      public void close()
      Description copied from interface: AxelorCache
      Signals that the cache is no longer in use and releases any resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface AxelorCache<K,V>
      Specified by:
      close in interface Closeable
    • estimatedSize

      public long estimatedSize()
      Description copied from interface: AxelorCache
      Returns the approximate number of entries in this cache. The actual count may differ because of concurrent updates and pending invalidations.
      Specified by:
      estimatedSize in interface AxelorCache<K,V>
      Returns:
      the estimated size of the cache
    • asMap

      public ConcurrentMap<K,V> asMap()
      Description copied from interface: AxelorCache
      Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to the map directly affect the cache.

      Note that if the cache has a cache loader, it will be used. This differs from Caffeine's Cache#asMap() and is designed to match Redisson RMap behavior.

      Specified by:
      asMap in interface AxelorCache<K,V>
      Returns:
      a thread-safe view of this cache supporting ConcurrentMap operations
    • getLock

      public Lock getLock(K key)
      Description copied from interface: AxelorCache
      Returns key-specific lock for this cache.
      Specified by:
      getLock in interface AxelorCache<K,V>
      Parameters:
      key -
      Returns:
      reentrant lock