session共享

登录缓存清理
缓存更换为redis缓存代码提交
This commit is contained in:
段冬梅
2018-12-16 11:04:25 +08:00
parent 22920b84cc
commit ed45211de9
11 changed files with 310 additions and 82 deletions

View File

@@ -1,10 +1,11 @@
package com.nis.util;
import org.apache.shiro.cache.Cache;
import org.crazycake.shiro.RedisCacheManager;
import com.nis.web.service.SpringContextHolder;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
/**
* Cache工具类
@@ -13,7 +14,7 @@ import net.sf.ehcache.Element;
*/
public class CacheUtils {
private static CacheManager cacheManager = ((CacheManager)SpringContextHolder.getBean("cacheManager"));
private static RedisCacheManager cacheManager = (RedisCacheManager)SpringContextHolder.getBean("shiroCacheManager");
private static final String SYS_CACHE = "sysCache";
@@ -51,8 +52,7 @@ public class CacheUtils {
* @return
*/
public static Object get(String cacheName, String key) {
Element element = getCache(cacheName).get(key);
return element==null?null:element.getObjectValue();
return getCache(cacheName).get(key);
}
/**
@@ -62,8 +62,8 @@ public class CacheUtils {
* @param value
*/
public static void put(String cacheName, String key, Object value) {
Element element = new Element(key, value);
getCache(cacheName).put(element);
Cache cache=cacheManager.getCache(cacheName);
cache.put(key, value);
}
/**
@@ -80,7 +80,7 @@ public class CacheUtils {
* @param cacheName
* @return
*/
private static Cache getCache(String cacheName){
/*private static Cache getCache(String cacheName){
Cache cache = cacheManager.getCache(cacheName);
if (cache == null){
cacheManager.addCache(cacheName);
@@ -88,9 +88,13 @@ public class CacheUtils {
cache.getCacheConfiguration().setEternal(true);
}
return cache;
}*/
private static Cache getCache(String cacheName){
Cache cache = cacheManager.getCache(cacheName);
return cache;
}
public static CacheManager getCacheManager() {
public static RedisCacheManager getCacheManager() {
return cacheManager;
}