|
|
@@ -3,6 +3,7 @@ package com.goafanti.core.shiro.cache;
|
|
|
import java.util.Collection;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.Set;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import org.apache.shiro.cache.Cache;
|
|
|
import org.apache.shiro.cache.CacheException;
|
|
|
@@ -18,6 +19,8 @@ public class ShiroRedisCache implements Cache<String, Object> {
|
|
|
|
|
|
private Set<String> emptySet = new HashSet<>();
|
|
|
|
|
|
+ private long expire = -1l;
|
|
|
+
|
|
|
public ShiroRedisCache() {
|
|
|
|
|
|
}
|
|
|
@@ -27,6 +30,12 @@ public class ShiroRedisCache implements Cache<String, Object> {
|
|
|
this.name = name;
|
|
|
}
|
|
|
|
|
|
+ public ShiroRedisCache(RedisTemplate<String, Object> redisTemplate, String name, long expire) {
|
|
|
+ this.redisTemplate = redisTemplate;
|
|
|
+ this.name = name;
|
|
|
+ this.expire = expire;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Object get(String key) throws CacheException {
|
|
|
if (key == null) {
|
|
|
@@ -42,7 +51,7 @@ public class ShiroRedisCache implements Cache<String, Object> {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- redisTemplate.opsForValue().set(decorateKey(key), value);
|
|
|
+ redisTemplate.opsForValue().set(decorateKey(key), value, expire, TimeUnit.SECONDS);
|
|
|
return value;
|
|
|
}
|
|
|
|