This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/util/CacheUtils.java
段冬梅 ed45211de9 session共享
登录缓存清理
缓存更换为redis缓存代码提交
2018-12-16 11:04:25 +08:00

102 lines
1.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nis.util;
import org.apache.shiro.cache.Cache;
import org.crazycake.shiro.RedisCacheManager;
import com.nis.web.service.SpringContextHolder;
/**
* Cache工具类
* @author darnell
*
*/
public class CacheUtils {
private static RedisCacheManager cacheManager = (RedisCacheManager)SpringContextHolder.getBean("shiroCacheManager");
private static final String SYS_CACHE = "sysCache";
/**
* 获取SYS_CACHE缓存
* @param key
* @return
*/
public static Object get(String key) {
return get(SYS_CACHE, key);
}
/**
* 写入SYS_CACHE缓存
* @param key
* @return
*/
public static void put(String key, Object value) {
put(SYS_CACHE, key, value);
}
/**
* 从SYS_CACHE缓存中移除
* @param key
* @return
*/
public static void remove(String key) {
remove(SYS_CACHE, key);
}
/**
* 获取缓存
* @param cacheName
* @param key
* @return
*/
public static Object get(String cacheName, String key) {
return getCache(cacheName).get(key);
}
/**
* 写入缓存
* @param cacheName
* @param key
* @param value
*/
public static void put(String cacheName, String key, Object value) {
Cache cache=cacheManager.getCache(cacheName);
cache.put(key, value);
}
/**
* 从缓存中移除
* @param cacheName
* @param key
*/
public static void remove(String cacheName, String key) {
getCache(cacheName).remove(key);
}
/**
* 获得一个Cache没有则创建一个。
* @param cacheName
* @return
*/
/*private static Cache getCache(String cacheName){
Cache cache = cacheManager.getCache(cacheName);
if (cache == null){
cacheManager.addCache(cacheName);
cache = cacheManager.getCache(cacheName);
cache.getCacheConfiguration().setEternal(true);
}
return cache;
}*/
private static Cache getCache(String cacheName){
Cache cache = cacheManager.getCache(cacheName);
return cache;
}
public static RedisCacheManager getCacheManager() {
return cacheManager;
}
}