Created
March 26, 2013 08:21
-
-
Save debop/5243856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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