Class CaffeineCache

java.lang.Object
org.springframework.cache.support.AbstractValueAdaptingCache
org.springframework.cache.caffeine.CaffeineCache
All Implemented Interfaces:
org.springframework.cache.Cache

public class CaffeineCache extends org.springframework.cache.support.AbstractValueAdaptingCache
Spring Cache adapter implementation on top of a Caffeine Cache instance.

Requires Caffeine 2.1 or higher.

Since:
4.3
Author:
Ben Manes, Juergen Hoeller, Stephane Nicoll
See Also:
  • Constructor Details

    • CaffeineCache

      public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object,Object> cache)
      Create a CaffeineCache instance with the specified name and the given internal Cache to use.
      Parameters:
      name - the name of the cache
      cache - the backing Caffeine Cache instance
    • CaffeineCache

      public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object,Object> cache, boolean allowNullValues)
      Create a CaffeineCache instance with the specified name and the given internal Cache to use.
      Parameters:
      name - the name of the cache
      cache - the backing Caffeine Cache instance
      allowNullValues - whether to accept and convert null values for this cache
  • Method Details

    • getName

      public final String getName()
    • getNativeCache

      public final com.github.benmanes.caffeine.cache.Cache<Object,Object> getNativeCache()
    • get

      @Nullable public <T> T get(Object key, Callable<T> valueLoader)
    • lookup

      @Nullable protected Object lookup(Object key)
      Specified by:
      lookup in class org.springframework.cache.support.AbstractValueAdaptingCache
    • put

      public void put(Object key, @Nullable Object value)
    • putIfAbsent

      @Nullable public org.springframework.cache.Cache.ValueWrapper putIfAbsent(Object key, @Nullable Object value)
    • evict

      public void evict(Object key)
    • evictIfPresent

      public boolean evictIfPresent(Object key)
    • clear

      public void clear()
    • invalidate

      public boolean invalidate()