You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
4.9 KiB
205 lines
4.9 KiB
/* */ package com.archive.common.utils
|
|
|
|
-INF.classes.com.archive.common.utils;
|
|
/* */
|
|
/* */ import com.archive.common.utils.spring.SpringUtils;
|
|
/* */ import java.util.Iterator;
|
|
/* */ import java.util.Set;
|
|
/* */ import org.apache.shiro.cache.Cache;
|
|
/* */ import org.apache.shiro.cache.CacheManager;
|
|
/* */ import org.apache.shiro.cache.ehcache.EhCacheManager;
|
|
/* */ import org.slf4j.Logger;
|
|
/* */ import org.slf4j.LoggerFactory;
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public class CacheUtils
|
|
/* */ {
|
|
/* 19 */ private static Logger logger = LoggerFactory.getLogger(com.archive.common.utils.CacheUtils.class);
|
|
/* */
|
|
/* 21 */ private static CacheManager cacheManager = (CacheManager)SpringUtils.getBean(CacheManager.class);
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ private static final String SYS_CACHE = "sys-cache";
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static Object get(String key) {
|
|
/* 33 */ return get("sys-cache", key);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static Object get(String key, Object defaultValue) {
|
|
/* 45 */ Object value = get(key);
|
|
/* 46 */ return (value != null) ? value : defaultValue;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static void put(String key, Object value) {
|
|
/* 57 */ put("sys-cache", key, value);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static void remove(String key) {
|
|
/* 68 */ remove("sys-cache", key);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static Object get(String cacheName, String key) {
|
|
/* 80 */ return getCache(cacheName).get(getKey(key));
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static Object get(String cacheName, String key, Object defaultValue) {
|
|
/* 93 */ Object value = get(cacheName, getKey(key));
|
|
/* 94 */ return (value != null) ? value : defaultValue;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static void put(String cacheName, String key, Object value) {
|
|
/* 106 */ getCache(cacheName).put(getKey(key), value);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static void remove(String cacheName, String key) {
|
|
/* 117 */ getCache(cacheName).remove(getKey(key));
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static void removeAll(String cacheName) {
|
|
/* 127 */ Cache<String, Object> cache = getCache(cacheName);
|
|
/* 128 */ Set<String> keys = cache.keys();
|
|
/* 129 */ for (Iterator<String> it = keys.iterator(); it.hasNext();)
|
|
/* */ {
|
|
/* 131 */ cache.remove(it.next());
|
|
/* */ }
|
|
/* 133 */ logger.info("清理缓存: {} => {}", cacheName, keys);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static void removeByKeys(Set<String> keys) {
|
|
/* 143 */ removeByKeys("sys-cache", keys);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static void removeByKeys(String cacheName, Set<String> keys) {
|
|
/* 154 */ for (Iterator<String> it = keys.iterator(); it.hasNext();)
|
|
/* */ {
|
|
/* 156 */ remove(it.next());
|
|
/* */ }
|
|
/* 158 */ logger.info("清理缓存: {} => {}", cacheName, keys);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ private static String getKey(String key) {
|
|
/* 169 */ return key;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static Cache<String, Object> getCache(String cacheName) {
|
|
/* 180 */ Cache<String, Object> cache = cacheManager.getCache(cacheName);
|
|
/* 181 */ if (cache == null)
|
|
/* */ {
|
|
/* 183 */ throw new RuntimeException("当前系统中没有定义“" + cacheName + "”这个缓存。");
|
|
/* */ }
|
|
/* 185 */ return cache;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public static String[] getCacheNames() {
|
|
/* 195 */ return ((EhCacheManager)cacheManager).getCacheManager().getCacheNames();
|
|
/* */ }
|
|
/* */ }
|
|
|
|
|
|
/* Location: C:\Users\Administrator\Desktop\extracted.zip!\extracted\BOOT-INF\classes\com\archive\commo\\utils\CacheUtils.class
|
|
* Java compiler version: 8 (52.0)
|
|
* JD-Core Version: 1.1.3
|
|
*/ |