Skip to content

Instantly share code, notes, and snippets.

@debop
Created March 26, 2013 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debop/5243856 to your computer and use it in GitHub Desktop.
Save debop/5243856 to your computer and use it in GitHub Desktop.
@Slf4j
public class RedisCacheManager extends AbstractTransactionSupportingCacheManager {
private RedisTemplate redisTemplate;
private int expireSeconds;
public RedisCacheManager(RedisTemplate redisTemplate) {
this(redisTemplate, 300);
}
public RedisCacheManager(RedisTemplate redisTemplate, int expireSeconds) {
Guard.shouldNotBeNull(redisTemplate, "redisTemplate");
this.redisTemplate = redisTemplate;
this.expireSeconds = expireSeconds;
}
@Override
protected Collection<? extends Cache> loadCaches() {
Collection<Cache> caches = Lists.newArrayList();
for (String name : getCacheNames()) {
caches.add(new RedisCache(name, redisTemplate, expireSeconds));
}
return caches;
}
@Override
public Cache getCache(String name) {
synchronized (this) {
Cache cache = super.getCache(name);
if (cache == null) {
cache = new RedisCache(name, redisTemplate, expireSeconds);
addCache(cache);
}
return cache;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment