ruoyi-common/ruoyi-common-redis/pom.xml
@@ -32,6 +32,11 @@ <groupId>com.baomidou</groupId> <artifactId>lock4j-redisson-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> </dependency> </dependencies> </project> ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/PlusCacheWrapper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,96 @@ package org.dromara.common.redis.manager; import cn.hutool.core.lang.Console; import com.github.benmanes.caffeine.cache.Caffeine; import org.springframework.cache.Cache; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; /** * Cache è£ é¥°å¨(ç¨äºæ©å±ä¸çº§ç¼å) * * @author LionLi */ public class PlusCacheWrapper implements Cache { private static final com.github.benmanes.caffeine.cache.Cache<Object, Object> CAFFEINE = Caffeine.newBuilder() // 设置æå䏿¬¡åå ¥æè®¿é®åç»è¿åºå®æ¶é´è¿æ .expireAfterWrite(30, TimeUnit.SECONDS) // åå§çç¼å空é´å¤§å° .initialCapacity(100) // ç¼åçæå¤§æ¡æ° .maximumSize(1000) .build(); private final Cache cache; public PlusCacheWrapper(Cache cache) { this.cache = cache; } @Override public String getName() { return cache.getName(); } @Override public Object getNativeCache() { return cache.getNativeCache(); } @Override public ValueWrapper get(Object key) { Object o = CAFFEINE.get(key, k -> cache.get(key)); Console.log("redisson caffeine -> key: " + key + ",value:" + o); return (ValueWrapper) o; } @SuppressWarnings("unchecked") public <T> T get(Object key, Class<T> type) { Object o = CAFFEINE.get(key, k -> cache.get(key, type)); Console.log("redisson caffeine -> key: " + key + ",value:" + o); return (T) o; } @Override public void put(Object key, Object value) { cache.put(key, value); CAFFEINE.put(key, value); } public ValueWrapper putIfAbsent(Object key, Object value) { return cache.putIfAbsent(key, value); } @Override public void evict(Object key) { evictIfPresent(key); } public boolean evictIfPresent(Object key) { boolean b = cache.evictIfPresent(key); if (b) { CAFFEINE.invalidate(key); } return b; } @Override public void clear() { cache.clear(); } public boolean invalidate() { return cache.invalidate(); } @SuppressWarnings("unchecked") @Override public <T> T get(Object key, Callable<T> valueLoader) { Object o = CAFFEINE.get(key, k -> cache.get(key, valueLoader)); Console.log("redisson caffeine -> key: " + key + ",value:" + o); return (T) o; } } ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/PlusSpringCacheManager.java
@@ -156,7 +156,7 @@ private Cache createMap(String name, CacheConfig config) { RMap<Object, Object> map = RedisUtils.getClient().getMap(name); Cache cache = new RedissonCache(map, allowNullValues); Cache cache = new PlusCacheWrapper(new RedissonCache(map, allowNullValues)); if (transactionAware) { cache = new TransactionAwareCacheDecorator(cache); } @@ -170,7 +170,7 @@ private Cache createMapCache(String name, CacheConfig config) { RMapCache<Object, Object> map = RedisUtils.getClient().getMapCache(name); Cache cache = new RedissonCache(map, config, allowNullValues); Cache cache = new PlusCacheWrapper(new RedissonCache(map, config, allowNullValues)); if (transactionAware) { cache = new TransactionAwareCacheDecorator(cache); } ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/core/dao/PlusSaTokenDao.java
@@ -15,6 +15,8 @@ /** * Sa-Tokenæä¹ 屿¥å£(ä½¿ç¨æ¡æ¶èªå¸¦RedisUtilså®ç° åè®®ç»ä¸) * <p> * éç¨ caffeine + redis å¤çº§ç¼å ä¼åå¹¶åæ¥è¯¢æç * * @author Lion Li */ @@ -22,7 +24,7 @@ private static final Cache<String, Object> CAFFEINE = Caffeine.newBuilder() // 设置æå䏿¬¡åå ¥æè®¿é®åç»è¿åºå®æ¶é´è¿æ .expireAfterWrite(10, TimeUnit.SECONDS) .expireAfterWrite(5, TimeUnit.SECONDS) // åå§çç¼å空é´å¤§å° .initialCapacity(100) // ç¼åçæå¤§æ¡æ° ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/config/SecurityConfig.java
@@ -59,9 +59,6 @@ StpUtil.getTokenValue()); } // ä¿åç¨æ·ä¿¡æ¯ // ThreadLocalHolder.set(LoginHelper.LOGIN_USER_KEY, LoginHelper.getLoginUser()); // ææçå½±å ç¨äºä¸´æ¶æµè¯ // if (log.isDebugEnabled()) { // log.info("å©ä½æææ¶é´: {}", StpUtil.getTokenTimeout()); @@ -69,14 +66,7 @@ // } }); }) // { // @Override // public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { // ThreadLocalHolder.clear(); // } // } ).addPathPatterns("/**") })).addPathPatterns("/**") // æé¤ä¸éè¦æ¦æªçè·¯å¾ .excludePathPatterns(securityProperties.getExcludes()); } ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDictTypeServiceImpl.java
@@ -6,9 +6,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.dromara.common.core.constant.CacheConstants; import lombok.RequiredArgsConstructor; import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.context.ThreadLocalHolder; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.service.DictService; import org.dromara.common.core.utils.MapstructUtils; @@ -26,7 +25,6 @@ import org.dromara.system.mapper.SysDictDataMapper; import org.dromara.system.mapper.SysDictTypeMapper; import org.dromara.system.service.ISysDictTypeService; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; @@ -217,16 +215,9 @@ * @param separator åé符 * @return åå ¸æ ç¾ */ @SuppressWarnings("unchecked cast") @Override public String getDictLabel(String dictType, String dictValue, String separator) { // ä¼å 仿¬å°ç¼åè·å List<SysDictDataVo> datas = ThreadLocalHolder.get(CacheConstants.SYS_DICT_KEY + dictType); if (ObjectUtil.isNull(datas)) { datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); ThreadLocalHolder.set(CacheConstants.SYS_DICT_KEY + dictType, datas); } List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel); if (StringUtils.containsAny(dictValue, separator)) { return Arrays.stream(dictValue.split(separator)) @@ -245,16 +236,9 @@ * @param separator åé符 * @return åå ¸å¼ */ @SuppressWarnings("unchecked cast") @Override public String getDictValue(String dictType, String dictLabel, String separator) { // ä¼å 仿¬å°ç¼åè·å List<SysDictDataVo> datas = ThreadLocalHolder.get(CacheConstants.SYS_DICT_KEY + dictType); if (ObjectUtil.isNull(datas)) { datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); ThreadLocalHolder.set(CacheConstants.SYS_DICT_KEY + dictType, datas); } List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue); if (StringUtils.containsAny(dictLabel, separator)) { return Arrays.stream(dictLabel.split(separator))