public class RedisCacheManager
extends org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
CacheManager
implementation for Redis. By default saves the keys directly, without appending a prefix (which
acts as a namespace). To avoid clashes, it is recommended to change this (by setting 'usePrefix' to 'true'). RedisCache
s will be lazily initialized for each getCache(String)
request unless a set of
predefined cache names is provided. AbstractTransactionSupportingCacheManager.setTransactionAware(boolean)
to true
will force Caches to be decorated as
TransactionAwareCacheDecorator
so values will only be written to the cache after successful commit of
surrounding transaction.Constructor and Description |
---|
RedisCacheManager(RedisTemplate template)
Construct a
RedisCacheManager . |
RedisCacheManager(RedisTemplate template,
Collection<String> cacheNames)
Construct a static
RedisCacheManager , managing caches for the specified cache names only. |
Modifier and Type | Method and Description |
---|---|
org.springframework.cache.Cache |
getCache(String name) |
protected Collection<? extends org.springframework.cache.Cache> |
loadCaches() |
void |
setCacheNames(Collection<String> cacheNames)
Specify the set of cache names for this CacheManager's 'static' mode.
|
void |
setCachePrefix(RedisCachePrefix cachePrefix)
Sets the cachePrefix.
|
void |
setDefaultExpiration(long defaultExpireTime)
Sets the default expire time (in seconds).
|
void |
setExpires(Map<String,Long> expires)
Sets the expire time (in seconds) for cache regions (by key).
|
void |
setLoadRemoteCachesOnStartup(boolean loadRemoteCachesOnStartup)
If set to
true RedisCacheManager will try to retrieve cache names from redis server using
KEYS command and initialize RedisCache for each of them. |
void |
setUsePrefix(boolean usePrefix) |
decorateCache, isTransactionAware, setTransactionAware
public RedisCacheManager(RedisTemplate template)
RedisCacheManager
.template
- public RedisCacheManager(RedisTemplate template, Collection<String> cacheNames)
RedisCacheManager
, managing caches for the specified cache names only.template
- cacheNames
- public org.springframework.cache.Cache getCache(String name)
getCache
in interface org.springframework.cache.CacheManager
getCache
in class org.springframework.cache.support.AbstractCacheManager
public void setCacheNames(Collection<String> cacheNames)
public void setUsePrefix(boolean usePrefix)
public void setCachePrefix(RedisCachePrefix cachePrefix)
cachePrefix
- the cachePrefix to setpublic void setDefaultExpiration(long defaultExpireTime)
defaultExpireTime
- time in seconds.public void setExpires(Map<String,Long> expires)
expires
- time in secondspublic void setLoadRemoteCachesOnStartup(boolean loadRemoteCachesOnStartup)
true
RedisCacheManager
will try to retrieve cache names from redis server using
KEYS command and initialize RedisCache
for each of them.loadRemoteCachesOnStartup
- protected Collection<? extends org.springframework.cache.Cache> loadCaches()
loadCaches
in class org.springframework.cache.support.AbstractCacheManager
Copyright © 2017 Pivotal Software, Inc.. All rights reserved.