shiro优化
parent
942e2b6083
commit
643fd81dbd
@ -1,88 +0,0 @@
|
||||
package cn.estsh.i3plus.core.apiservice.auth;
|
||||
|
||||
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : alwaysfrin
|
||||
* @CreateDate : 2018-10-16 11:24
|
||||
* @Modify:
|
||||
**/
|
||||
@Service
|
||||
public class ShiroEhCacheImpl<K, V> implements Cache<K, V> {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(ShiroEhCacheImpl.class);
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("redisSession")
|
||||
private ImppRedis imppRedis;
|
||||
|
||||
@Override
|
||||
public V get(K o) throws CacheException {
|
||||
System.out.println("================"+imppRedis);
|
||||
LOGGER.info("【ehcache获取】{}",o);
|
||||
return (V) imppRedis.getObject(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(K key, V value) throws CacheException {
|
||||
LOGGER.info("【ehcache放入】{}:{}",key,value);
|
||||
V oldObj = get(key);
|
||||
imppRedis.putObject(key.toString(),value, 18000);
|
||||
return oldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V remove(K o) throws CacheException {
|
||||
V oldObj = get(o);
|
||||
//删除
|
||||
imppRedis.deleteKey(o.toString());
|
||||
|
||||
return oldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws CacheException {
|
||||
Set<String> keySet = keys();
|
||||
for(String key : keySet){
|
||||
imppRedis.deleteKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return keys().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set keys() {
|
||||
return imppRedis.getKeysSet(CommonConstWords.CACHE_SESSION_PREFX + "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection values() {
|
||||
List<Object> list = new ArrayList<>();
|
||||
Set<K> keySet = keys();
|
||||
for (K s : keySet) {
|
||||
list.add(get(s));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package cn.estsh.i3plus.core.apiservice.auth;
|
||||
|
||||
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheException;
|
||||
import org.apache.shiro.session.mgt.SimpleSession;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : alwaysfrin
|
||||
* @CreateDate : 2018-10-16 11:24
|
||||
* @Modify:
|
||||
**/
|
||||
@Service
|
||||
public class ShiroRedisCacheImpl<K, V> implements Cache<K, V> {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(ShiroRedisCacheImpl.class);
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
*/
|
||||
@Resource(name="redisSession")
|
||||
private ImppRedis imppRedis;
|
||||
|
||||
@Override
|
||||
public V get(K o) throws CacheException {
|
||||
return (V) imppRedis.getObject(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(K key, V value) throws CacheException {
|
||||
V oldObj = get(key);
|
||||
imppRedis.putObject(key.toString(),value, 18000);
|
||||
return oldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V remove(K o) throws CacheException {
|
||||
V oldObj = get(o);
|
||||
//删除
|
||||
imppRedis.deleteKey(o.toString());
|
||||
|
||||
return oldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws CacheException {
|
||||
Set<String> keySet = keys();
|
||||
for(String key : keySet){
|
||||
imppRedis.deleteKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return keys().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set keys() {
|
||||
return imppRedis.getKeysSet(CommonConstWords.CACHE_SESSION_PREFX + "*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection values() {
|
||||
List<Object> list = new ArrayList<>();
|
||||
Set<K> keySet = keys();
|
||||
for (K s : keySet) {
|
||||
list.add(get(s));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package cn.estsh.i3plus.core.apiservice.auth;
|
||||
|
||||
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheException;
|
||||
import org.apache.shiro.cache.CacheManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @Description : 授权缓存管理
|
||||
* @Reference :
|
||||
* @Author : alwaysfrin
|
||||
* @CreateDate : 2018-10-16 13:26
|
||||
* @Modify:
|
||||
**/
|
||||
public class ShiroRedisCacheManager implements CacheManager {
|
||||
|
||||
@Autowired
|
||||
private ShiroRedisCacheImpl redisCacheImpl;
|
||||
|
||||
@Autowired
|
||||
private ShiroRedisCacheImpl ehCacheImpl;
|
||||
|
||||
@Override
|
||||
public <K, V> Cache<K, V> getCache(String s) throws CacheException {
|
||||
//return redisCacheImpl;
|
||||
return ehCacheImpl;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue