Class CaffeineLoadingCache<K,V>

java.lang.Object
com.axelor.cache.caffeine.CaffeineCache<K,V>
com.axelor.cache.caffeine.CaffeineLoadingCache<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>>

public class CaffeineLoadingCache<K,V> extends CaffeineCache<K,V>
Caffeine loading cache

This wraps a LoadingCache.

In order to match with Redisson behavior, cache loader is always used (normally, Caffeine's get(key, mappingFunction) and asMap() operations skip cache loader).

  • Field Details

  • Constructor Details

    • CaffeineLoadingCache

      public CaffeineLoadingCache(com.github.benmanes.caffeine.cache.LoadingCache<K,V> cache, CacheLoader<? super K,V> loader)
  • Method Details

    • 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>
      Overrides:
      get in class CaffeineCache<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>
      Overrides:
      getAll in class CaffeineCache<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
    • get

      public V get(K key, Function<? super K,? extends V> mappingFunction)
      Try cache loader before mapping function for consistency with Redisson.
      Specified by:
      get in interface AxelorCache<K,V>
      Overrides:
      get in class CaffeineCache<K,V>
      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
    • 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>
      Overrides:
      asMap in class CaffeineCache<K,V>
      Returns:
      a thread-safe view of this cache supporting ConcurrentMap operations