类 CaffeineCacheManager
- 所有已实现的接口:
CacheManager
CacheManager implementation that lazily builds CaffeineCache
instances for each getCache(java.lang.String) request. Also supports a 'static' mode
where the set of cache names is pre-defined through setCacheNames(java.util.Collection<java.lang.String>),
with no dynamic creation of further cache regions at runtime.
The configuration of the underlying cache can be fine-tuned through a
Caffeine builder or CaffeineSpec, passed into this
CacheManager through setCaffeine(com.github.benmanes.caffeine.cache.Caffeine<java.lang.Object, java.lang.Object>)/setCaffeineSpec(com.github.benmanes.caffeine.cache.CaffeineSpec).
A CaffeineSpec-compliant expression value can also be applied
via the "cacheSpecification" bean property.
Requires Caffeine 2.1 or higher.
- 从以下版本开始:
- 2020-08-15 20:05
- 作者:
- Ben Manes, Juergen Hoeller, Stephane Nicoll, Sam Brannen, TODAY
- 另请参阅:
-
构造器概要
构造器构造器说明Construct a dynamic CaffeineCacheManager, lazily creating cache instances as they are being requested.CaffeineCacheManager(String... cacheNames) Construct a static CaffeineCacheManager, managing caches for the specified cache names only. -
方法概要
修饰符和类型方法说明protected CacheadaptCaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache) Adapt the given new native Caffeine Cache instance to Framework'sCacheabstraction for the specified cache name.protected CachecreateCaffeineCache(String name) Build a commonCaffeineCacheinstance for the specified cache name, using the common Caffeine configuration specified on this cache manager.Build a common Caffeine Cache instance for the specified cache name, using the common Caffeine configuration specified on this cache manager.Get the cache associated with the given name.Get a collection of the cache names known by this manager.booleanReturn whether this cache manager accepts and convertsnullvalues for all of its caches.voidregisterCustomCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache) Register the given native Caffeine Cache instance with this cache manager, adapting it to Framework's cache API for exposure throughgetCache(java.lang.String).voidsetAllowNullValues(boolean allowNullValues) Specify whether to accept and convertnullvalues for all caches in this cache manager.voidsetCacheLoader(com.github.benmanes.caffeine.cache.CacheLoader<Object, Object> cacheLoader) Set the Caffeine CacheLoader to use for building each individualCaffeineCacheinstance, turning it into a LoadingCache.voidsetCacheNames(Collection<String> cacheNames) Specify the set of cache names for this CacheManager's 'static' mode.voidsetCacheSpecification(String cacheSpecification) Set the Caffeine cache specification String to use for building each individualCaffeineCacheinstance.voidsetCaffeine(com.github.benmanes.caffeine.cache.Caffeine<Object, Object> caffeine) Set the Caffeine to use for building each individualCaffeineCacheinstance.voidsetCaffeineSpec(com.github.benmanes.caffeine.cache.CaffeineSpec caffeineSpec) Set theCaffeineSpecto use for building each individualCaffeineCacheinstance.
-
构造器详细资料
-
CaffeineCacheManager
public CaffeineCacheManager()Construct a dynamic CaffeineCacheManager, lazily creating cache instances as they are being requested. -
CaffeineCacheManager
Construct a static CaffeineCacheManager, managing caches for the specified cache names only.
-
-
方法详细资料
-
setCacheNames
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
nullcollection argument resets the mode to 'dynamic', allowing for further creation of caches again. -
setCaffeine
Set the Caffeine to use for building each individualCaffeineCacheinstance.- 另请参阅:
-
createNativeCaffeineCache(java.lang.String)Caffeine.build()
-
setCaffeineSpec
public void setCaffeineSpec(com.github.benmanes.caffeine.cache.CaffeineSpec caffeineSpec) Set theCaffeineSpecto use for building each individualCaffeineCacheinstance.- 另请参阅:
-
createNativeCaffeineCache(java.lang.String)Caffeine.from(CaffeineSpec)
-
setCacheSpecification
Set the Caffeine cache specification String to use for building each individualCaffeineCacheinstance. The given value needs to comply with Caffeine'sCaffeineSpec(see its javadoc).- 另请参阅:
-
createNativeCaffeineCache(java.lang.String)Caffeine.from(String)
-
setCacheLoader
public void setCacheLoader(com.github.benmanes.caffeine.cache.CacheLoader<Object, Object> cacheLoader) Set the Caffeine CacheLoader to use for building each individualCaffeineCacheinstance, turning it into a LoadingCache.- 另请参阅:
-
createNativeCaffeineCache(java.lang.String)Caffeine.build(CacheLoader)LoadingCache
-
setAllowNullValues
public void setAllowNullValues(boolean allowNullValues) Specify whether to accept and convertnullvalues for all caches in this cache manager.Default is "true", despite Caffeine itself not supporting
nullvalues. An internal holder object will be used to store user-levelnulls. -
isAllowNullValues
public boolean isAllowNullValues()Return whether this cache manager accepts and convertsnullvalues for all of its caches. -
getCacheNames
从接口复制的说明:CacheManagerGet a collection of the cache names known by this manager.- 指定者:
getCacheNames在接口中CacheManager- 返回:
- the names of all caches known by the cache manager
-
getCache
从接口复制的说明:CacheManagerGet the cache associated with the given name.Note that the cache may be lazily created at runtime if the native provider supports it.
- 指定者:
getCache在接口中CacheManager- 参数:
name- the cache identifier (must not benull)- 返回:
- the associated cache, or
nullif such a cache does not exist or could be not created
-
registerCustomCache
public void registerCustomCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache) Register the given native Caffeine Cache instance with this cache manager, adapting it to Framework's cache API for exposure throughgetCache(java.lang.String). Any number of such custom caches may be registered side by side.This allows for custom settings per cache (as opposed to all caches sharing the common settings in the cache manager's configuration) and is typically used with the Caffeine builder API:
registerCustomCache("myCache", Caffeine.newBuilder().maximumSize(10).build())Note that any other caches, whether statically specified through
setCacheNames(java.util.Collection<java.lang.String>)or dynamically built on demand, still operate with the common settings in the cache manager's configuration.- 参数:
name- the name of the cachecache- the custom Caffeine Cache instance to register- 另请参阅:
-
adaptCaffeineCache
protected Cache adaptCaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache) Adapt the given new native Caffeine Cache instance to Framework'sCacheabstraction for the specified cache name.- 参数:
name- the name of the cachecache- the native Caffeine Cache instance- 返回:
- the FrameworkCaffeineCache adapter (or a decorator thereof)
- 另请参阅:
-
createCaffeineCache
Build a commonCaffeineCacheinstance for the specified cache name, using the common Caffeine configuration specified on this cache manager.Delegates to
adaptCaffeineCache(java.lang.String, com.github.benmanes.caffeine.cache.Cache<java.lang.Object, java.lang.Object>)as the adaptation method to Framework's cache abstraction (allowing for centralized decoration etc), passing in a freshly built native Caffeine Cache instance.- 参数:
name- the name of the cache- 返回:
- the FrameworkCaffeineCache adapter (or a decorator thereof)
- 另请参阅:
-
createNativeCaffeineCache
protected com.github.benmanes.caffeine.cache.Cache<Object,Object> createNativeCaffeineCache(String name) Build a common Caffeine Cache instance for the specified cache name, using the common Caffeine configuration specified on this cache manager.- 参数:
name- the name of the cache- 返回:
- the native Caffeine Cache instance
- 另请参阅:
-