public class SpringCache2kCacheManager extends Object implements org.springframework.cache.CacheManager
CacheManager. The available caches can be
configured programmatically in a Spring configuration class via the use
of addCaches(Function[]), via a Spring XML configuration
and setCaches(Collection) or via the cache2k XML configuration.| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_SPRING_CACHE_MANAGER_NAME
Default name used for the cache2k cache manager controlled by the spring cache
manager.
|
| Constructor and Description |
|---|
SpringCache2kCacheManager()
Construct a spring cache manager, using the cache2k cache manager with
the name "springDefault".
|
SpringCache2kCacheManager(org.cache2k.CacheManager manager)
Construct a spring cache manager, using a custom cache2k cache manager.
|
SpringCache2kCacheManager(String name)
Construct a spring cache manager, using the cache2k cache manager instance
with the specified name.
|
| Modifier and Type | Method and Description |
|---|---|
SpringCache2kCacheManager |
addCaches(Function<org.cache2k.Cache2kBuilder<?,?>,org.cache2k.Cache2kBuilder<?,?>>... fs)
Adds a caches to this cache manager that maybe is configured via the
Cache2kBuilder. |
SpringCache2kCacheManager |
defaultSetup(Function<org.cache2k.Cache2kBuilder<?,?>,org.cache2k.Cache2kBuilder<?,?>> f)
Function providing default settings for caches added to the manager via
addCaches(java.util.function.Function<org.cache2k.Cache2kBuilder<?, ?>, org.cache2k.Cache2kBuilder<?, ?>>...) |
SpringCache2kCache |
getCache(String name)
Returns an existing cache or retrieves and wraps a cache from cache2k.
|
Map<String,SpringCache2kCache> |
getCacheMap()
Expose the map of created and wrapped caches.
|
Collection<String> |
getCacheNames()
Get a list of known caches.
|
Collection<String> |
getConfiguredCacheNames()
List of configured cache names.
|
org.cache2k.CacheManager |
getNativeCacheManager()
Expose the native cache manager.
|
boolean |
isAllowUnknownCache() |
void |
setAllowUnknownCache(boolean v)
If
false, the cache manager only manages a cache if added via addCaches(java.util.function.Function<org.cache2k.Cache2kBuilder<?, ?>, org.cache2k.Cache2kBuilder<?, ?>>...),
setCaches(Collection) or enlisted in the cache2k XML configuration. |
void |
setCaches(Collection<org.cache2k.configuration.Cache2kConfiguration<?,?>> cacheConfigurationList)
Configure the known caches via the configuration bean.
|
public static final String DEFAULT_SPRING_CACHE_MANAGER_NAME
public SpringCache2kCacheManager()
CacheManagerpublic SpringCache2kCacheManager(String name)
CacheManager,
CacheManager.getInstance()public SpringCache2kCacheManager(org.cache2k.CacheManager manager)
CacheManager,
CacheManager.getInstance(String),
CacheManager.getInstance(ClassLoader),
CacheManager.getInstance(ClassLoader, String)public SpringCache2kCache getCache(String name)
getCache in interface org.springframework.cache.CacheManagerpublic SpringCache2kCacheManager defaultSetup(Function<org.cache2k.Cache2kBuilder<?,?>,org.cache2k.Cache2kBuilder<?,?>> f)
addCaches(java.util.function.Function<org.cache2k.Cache2kBuilder<?, ?>, org.cache2k.Cache2kBuilder<?, ?>>...)@SafeVarargs public final SpringCache2kCacheManager addCaches(Function<org.cache2k.Cache2kBuilder<?,?>,org.cache2k.Cache2kBuilder<?,?>>... fs)
Cache2kBuilder.
The configuration parameter Cache2kBuilder.exceptionPropagator(org.cache2k.integration.ExceptionPropagator<K>)
is managed by this class and cannot be used. This method can be used in case a programmatic
configuration of a cache manager is preferred.
Rationale: The method provides a builder that is already seeded with the effective cache2k cache manager. This makes it possible to use the builder without code bloat. Since the actual build is done within this class, it is also possible to reset specific settings or do assertions.
IllegalArgumentException - if cache is already createdpublic void setCaches(Collection<org.cache2k.configuration.Cache2kConfiguration<?,?>> cacheConfigurationList)
public Collection<String> getCacheNames()
getCacheNames in interface org.springframework.cache.CacheManagerpublic Collection<String> getConfiguredCacheNames()
addCache(org.cache2k.Cache2kBuilder<?, ?>).
Used for testing purposes to determine whether a cache was added dynamically.public org.cache2k.CacheManager getNativeCacheManager()
public Map<String,SpringCache2kCache> getCacheMap()
public boolean isAllowUnknownCache()
public void setAllowUnknownCache(boolean v)
false, the cache manager only manages a cache if added via addCaches(java.util.function.Function<org.cache2k.Cache2kBuilder<?, ?>, org.cache2k.Cache2kBuilder<?, ?>>...),
setCaches(Collection) or enlisted in the cache2k XML configuration.
Setting this to true will create a cache with a default configuration if the requested
cache name is not known. The default is true.cache2k API documentation. Copyright © 2000–2020 headissue GmbH, Munich.