org.springframework.cache.caffeine

Class CaffeineCacheManager

  • java.lang.Object
    • org.springframework.cache.caffeine.CaffeineCacheManager
    • Constructor Summary

      Constructors 
      Constructor and Description
      CaffeineCacheManager()
      Construct a dynamic CaffeineCacheManager, lazily creating cache instances as they are being requested.
      CaffeineCacheManager(java.lang.String... cacheNames)
      Construct a static CaffeineCacheManager, managing caches for the specified cache names only.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      protected Cache createCaffeineCache(java.lang.String name)
      Create a new CaffeineCache instance for the specified cache name.
      protected com.github.benmanes.caffeine.cache.Cache<java.lang.Object,java.lang.Object> createNativeCaffeineCache(java.lang.String name)
      Create a native Caffeine Cache instance for the specified cache name.
      Cache getCache(java.lang.String name)
      Return the cache associated with the given name.
      java.util.Collection<java.lang.String> getCacheNames()
      Return a collection of the cache names known by this manager.
      boolean isAllowNullValues()
      Return whether this cache manager accepts and converts null values for all of its caches.
      void setAllowNullValues(boolean allowNullValues)
      Specify whether to accept and convert null values for all caches in this cache manager.
      void setCacheLoader(com.github.benmanes.caffeine.cache.CacheLoader<java.lang.Object,java.lang.Object> cacheLoader)
      Set the Caffeine CacheLoader to use for building each individual CaffeineCache instance, turning it into a LoadingCache.
      void setCacheNames(java.util.Collection<java.lang.String> cacheNames)
      Specify the set of cache names for this CacheManager's 'static' mode.
      void setCacheSpecification(java.lang.String cacheSpecification)
      Set the Caffeine cache specification String to use for building each individual CaffeineCache instance.
      void setCaffeine(com.github.benmanes.caffeine.cache.Caffeine<java.lang.Object,java.lang.Object> caffeine)
      Set the Caffeine to use for building each individual CaffeineCache instance.
      void setCaffeineSpec(com.github.benmanes.caffeine.cache.CaffeineSpec caffeineSpec)
      Set the CaffeineSpec to use for building each individual CaffeineCache instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CaffeineCacheManager

        public CaffeineCacheManager()
        Construct a dynamic CaffeineCacheManager, lazily creating cache instances as they are being requested.
      • CaffeineCacheManager

        public CaffeineCacheManager(java.lang.String... cacheNames)
        Construct a static CaffeineCacheManager, managing caches for the specified cache names only.
    • Method Detail

      • setCacheNames

        public void setCacheNames(@Nullable
                                  java.util.Collection<java.lang.String> cacheNames)
        Specify the set of cache names for this CacheManager's 'static' mode.

        The number of caches and their names will be fixed after a call to this method, with no creation of further cache regions at runtime.

        Calling this with a null collection argument resets the mode to 'dynamic', allowing for further creation of caches again.

      • setCacheSpecification

        public void setCacheSpecification(java.lang.String cacheSpecification)
        Set the Caffeine cache specification String to use for building each individual CaffeineCache instance. The given value needs to comply with Caffeine's CaffeineSpec (see its javadoc).
        See Also:
        createNativeCaffeineCache(java.lang.String), Caffeine.from(String)
      • setCacheLoader

        public void setCacheLoader(com.github.benmanes.caffeine.cache.CacheLoader<java.lang.Object,java.lang.Object> cacheLoader)
        Set the Caffeine CacheLoader to use for building each individual CaffeineCache instance, turning it into a LoadingCache.
        See Also:
        createNativeCaffeineCache(java.lang.String), Caffeine.build(CacheLoader), LoadingCache
      • setAllowNullValues

        public void setAllowNullValues(boolean allowNullValues)
        Specify whether to accept and convert null values for all caches in this cache manager.

        Default is "true", despite Caffeine itself not supporting null values. An internal holder object will be used to store user-level nulls.

      • isAllowNullValues

        public boolean isAllowNullValues()
        Return whether this cache manager accepts and converts null values for all of its caches.
      • getCacheNames

        public java.util.Collection<java.lang.String> getCacheNames()
        Description copied from interface: CacheManager
        Return a collection of the cache names known by this manager.
        Specified by:
        getCacheNames in interface CacheManager
        Returns:
        the names of all caches known by the cache manager
      • getCache

        @Nullable
        public Cache getCache(java.lang.String name)
        Description copied from interface: CacheManager
        Return the cache associated with the given name.
        Specified by:
        getCache in interface CacheManager
        Parameters:
        name - the cache identifier (must not be null)
        Returns:
        the associated cache, or null if none found
      • createCaffeineCache

        protected Cache createCaffeineCache(java.lang.String name)
        Create a new CaffeineCache instance for the specified cache name.
        Parameters:
        name - the name of the cache
        Returns:
        the Spring CaffeineCache adapter (or a decorator thereof)
      • createNativeCaffeineCache

        protected com.github.benmanes.caffeine.cache.Cache<java.lang.Object,java.lang.Object> createNativeCaffeineCache(java.lang.String name)
        Create a native Caffeine Cache instance for the specified cache name.
        Parameters:
        name - the name of the cache
        Returns:
        the native Caffeine Cache instance