类 ConcurrentMapCacheManager
- java.lang.Object
- org.springframework.cache.concurrent.ConcurrentMapCacheManager
- 所有已实现的接口:
Aware
,BeanClassLoaderAware
,CacheManager
public class ConcurrentMapCacheManager extends Object implements CacheManager, BeanClassLoaderAware
CacheManager
implementation that lazily buildsConcurrentMapCache
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.Note: This is by no means a sophisticated CacheManager; it comes with no cache configuration options. However, it may be useful for testing or simple caching scenarios. For advanced local caching needs, consider
JCacheCacheManager
,EhCacheCacheManager
,CaffeineCacheManager
.- 从以下版本开始:
- 3.1
- 作者:
- Juergen Hoeller
- 另请参阅:
ConcurrentMapCache
构造器概要
构造器 构造器 说明 ConcurrentMapCacheManager()
Construct a dynamic ConcurrentMapCacheManager, lazily creating cache instances as they are being requested.ConcurrentMapCacheManager(String... cacheNames)
Construct a static ConcurrentMapCacheManager, managing caches for the specified cache names only.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Cache
createConcurrentMapCache(String name)
Create a new ConcurrentMapCache 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.boolean
isStoreByValue()
Return whether this cache manager stores a copy of each entry or a reference for all its caches.void
setAllowNullValues(boolean allowNullValues)
Specify whether to accept and convertnull
values for all caches in this cache manager.void
setBeanClassLoader(ClassLoader classLoader)
Callback that supplies the beanclass loader
to a bean instance.void
setCacheNames(Collection<String> cacheNames)
Specify the set of cache names for this CacheManager's 'static' mode.void
setStoreByValue(boolean storeByValue)
Specify whether this cache manager stores a copy of each entry (true
or the reference (false
for all of its caches.
构造器详细资料
ConcurrentMapCacheManager
public ConcurrentMapCacheManager()
Construct a dynamic ConcurrentMapCacheManager, lazily creating cache instances as they are being requested.
ConcurrentMapCacheManager
public ConcurrentMapCacheManager(String... cacheNames)
Construct a static ConcurrentMapCacheManager, managing caches for the specified cache names only.
方法详细资料
setCacheNames
public void setCacheNames(@Nullable 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.
setAllowNullValues
public void setAllowNullValues(boolean allowNullValues)
Specify whether to accept and convertnull
values for all caches in this cache manager.Default is "true", despite ConcurrentHashMap itself not supporting
null
values. An internal holder object will be used to store user-levelnull
s.Note: A change of the null-value setting will reset all existing caches, if any, to reconfigure them with the new null-value requirement.
isAllowNullValues
public boolean isAllowNullValues()
Return whether this cache manager accepts and convertsnull
values for all of its caches.
setStoreByValue
public void setStoreByValue(boolean storeByValue)
Specify whether this cache manager stores a copy of each entry (true
or the reference (false
for all of its caches.Default is "false" so that the value itself is stored and no serializable contract is required on cached values.
Note: A change of the store-by-value setting will reset all existing caches, if any, to reconfigure them with the new store-by-value requirement.
- 从以下版本开始:
- 4.3
isStoreByValue
public boolean isStoreByValue()
Return whether this cache manager stores a copy of each entry or a reference for all its caches. If store by value is enabled, any cache entry must be serializable.- 从以下版本开始:
- 4.3
setBeanClassLoader
public void setBeanClassLoader(ClassLoader classLoader)
从接口复制的说明:BeanClassLoaderAware
Callback that supplies the beanclass loader
to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.- 指定者:
setBeanClassLoader
在接口中BeanClassLoaderAware
- 参数:
classLoader
- the owning class loader
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
@Nullable 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
createConcurrentMapCache
protected Cache createConcurrentMapCache(String name)
Create a new ConcurrentMapCache instance for the specified cache name.- 参数:
name
- the name of the cache- 返回:
- the ConcurrentMapCache (or a decorator thereof)