类 GuavaCacheManager
- java.lang.Object
- org.springframework.cache.guava.GuavaCacheManager
- 所有已实现的接口:
CacheManager
public class GuavaCacheManager extends Object implements CacheManager
CacheManager
implementation that lazily buildsGuavaCache
instances for eachgetCache(java.lang.String)
request. Also supports a 'static' mode where the set of cache names is pre-defined throughsetCacheNames(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 Guava
CacheBuilder
orCacheBuilderSpec
, passed into this CacheManager throughsetCacheBuilder(com.google.common.cache.CacheBuilder<java.lang.Object, java.lang.Object>)
/setCacheBuilderSpec(com.google.common.cache.CacheBuilderSpec)
. ACacheBuilderSpec
-compliant expression value can also be applied via the"cacheSpecification"
bean property.Requires Google Guava 12.0 or higher.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller, Stephane Nicoll
- 另请参阅:
GuavaCache
构造器概要
构造器 构造器 说明 GuavaCacheManager()
Construct a dynamic GuavaCacheManager, lazily creating cache instances as they are being requested.GuavaCacheManager(String... cacheNames)
Construct a static GuavaCacheManager, managing caches for the specified cache names only.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Cache
createGuavaCache(String name)
Create a new GuavaCache instance for the specified cache name.protected com.google.common.cache.Cache<Object,Object>
createNativeGuavaCache(String name)
Create a native Guava Cache instance for the specified cache name.Cache
getCache(String name)
Get the cache associated with the given name.Collection<String>
getCacheNames()
Get a collection of the cache names known by this manager.boolean
isAllowNullValues()
Return whether this cache manager accepts and convertsnull
values for all of its caches.void
setAllowNullValues(boolean allowNullValues)
Specify whether to accept and convertnull
values for all caches in this cache manager.void
setCacheBuilder(com.google.common.cache.CacheBuilder<Object,Object> cacheBuilder)
Set the Guava CacheBuilder to use for building each individualGuavaCache
instance.void
setCacheBuilderSpec(com.google.common.cache.CacheBuilderSpec cacheBuilderSpec)
Set the Guava CacheBuilderSpec to use for building each individualGuavaCache
instance.void
setCacheLoader(com.google.common.cache.CacheLoader<Object,Object> cacheLoader)
Set the Guava CacheLoader to use for building each individualGuavaCache
instance, turning it into a LoadingCache.void
setCacheNames(Collection<String> cacheNames)
Specify the set of cache names for this CacheManager's 'static' mode.void
setCacheSpecification(String cacheSpecification)
Set the Guava cache specification String to use for building each individualGuavaCache
instance.
构造器详细资料
GuavaCacheManager
public GuavaCacheManager()
Construct a dynamic GuavaCacheManager, lazily creating cache instances as they are being requested.
GuavaCacheManager
public GuavaCacheManager(String... cacheNames)
Construct a static GuavaCacheManager, managing caches for the specified cache names only.
方法详细资料
setCacheNames
public void setCacheNames(Collection<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.
setCacheBuilder
public void setCacheBuilder(com.google.common.cache.CacheBuilder<Object,Object> cacheBuilder)
Set the Guava CacheBuilder to use for building each individualGuavaCache
instance.- 另请参阅:
createNativeGuavaCache(java.lang.String)
,CacheBuilder.build()
setCacheBuilderSpec
public void setCacheBuilderSpec(com.google.common.cache.CacheBuilderSpec cacheBuilderSpec)
Set the Guava CacheBuilderSpec to use for building each individualGuavaCache
instance.- 另请参阅:
createNativeGuavaCache(java.lang.String)
,CacheBuilder.from(CacheBuilderSpec)
setCacheSpecification
public void setCacheSpecification(String cacheSpecification)
Set the Guava cache specification String to use for building each individualGuavaCache
instance. The given value needs to comply with Guava'sCacheBuilderSpec
(see its javadoc).- 另请参阅:
createNativeGuavaCache(java.lang.String)
,CacheBuilder.from(String)
setCacheLoader
public void setCacheLoader(com.google.common.cache.CacheLoader<Object,Object> cacheLoader)
Set the Guava CacheLoader to use for building each individualGuavaCache
instance, turning it into a LoadingCache.- 另请参阅:
createNativeGuavaCache(java.lang.String)
,CacheBuilder.build(CacheLoader)
,LoadingCache
setAllowNullValues
public void setAllowNullValues(boolean allowNullValues)
Specify whether to accept and convertnull
values for all caches in this cache manager.Default is "true", despite Guava itself not supporting
null
values. An internal holder object will be used to store user-levelnull
s.
isAllowNullValues
public boolean isAllowNullValues()
Return whether this cache manager accepts and convertsnull
values for all of its caches.
getCacheNames
public Collection<String> getCacheNames()
从接口复制的说明:CacheManager
Get a collection of the cache names known by this manager.- 指定者:
getCacheNames
在接口中CacheManager
- 返回:
- the names of all caches known by the cache manager
getCache
public Cache getCache(String name)
从接口复制的说明:CacheManager
Get 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
null
if such a cache does not exist or could be not created
createGuavaCache
protected Cache createGuavaCache(String name)
Create a new GuavaCache instance for the specified cache name.- 参数:
name
- the name of the cache- 返回:
- the Spring GuavaCache adapter (or a decorator thereof)
createNativeGuavaCache
protected com.google.common.cache.Cache<Object,Object> createNativeGuavaCache(String name)
Create a native Guava Cache instance for the specified cache name.- 参数:
name
- the name of the cache- 返回:
- the native Guava Cache instance