From 2c785c3d4513daea9deb5c7edbb17a9f17111d25 Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期五, 21 二月 2025 17:49:03 +0800 Subject: [PATCH] zjh20250221 --- ltkj-system/src/main/java/com/ltkj/tduck/utils/CacheUtils.java | 49 +++++++++++++++++++++++++++++-------------------- 1 files changed, 29 insertions(+), 20 deletions(-) diff --git a/ltkj-system/src/main/java/com/ltkj/tduck/utils/CacheUtils.java b/ltkj-system/src/main/java/com/ltkj/tduck/utils/CacheUtils.java index 7f5c037..b828b20 100644 --- a/ltkj-system/src/main/java/com/ltkj/tduck/utils/CacheUtils.java +++ b/ltkj-system/src/main/java/com/ltkj/tduck/utils/CacheUtils.java @@ -3,12 +3,12 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.ltkj.common.core.redis.RedisCache; import lombok.extern.slf4j.Slf4j; import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.stereotype.Component; import java.util.List; @@ -24,14 +24,17 @@ public class CacheUtils { private final String ETERNAL_CACHE_NAME = "eternal_cache"; private final String TEMP_CACHE_NAME = "temp_cache"; +// @Autowired +// private EhCacheCacheManager cacheManager; @Autowired - private EhCacheCacheManager cacheManager; + private RedisCache cache; /** * 淇濆瓨鍒癈ache */ public void save(String key, String value) { - cacheManager.getCache(ETERNAL_CACHE_NAME).put(key, value); +// cacheManager.getCache(ETERNAL_CACHE_NAME).put(key, value); + cache.setCacheObject(key,value); } /** @@ -40,9 +43,14 @@ * @param key */ public String get(String key) { - Cache.ValueWrapper valueWrapper = cacheManager.getCache(ETERNAL_CACHE_NAME).get(key); - if (ObjectUtil.isNotNull(valueWrapper) && ObjectUtil.isNotNull(valueWrapper.get())) { - return valueWrapper.get().toString(); +// Cache.ValueWrapper valueWrapper = cacheManager.getCache(ETERNAL_CACHE_NAME).get(key); +// Cache.ValueWrapper valueWrapper = cache.getCacheObject(key); +// if (ObjectUtil.isNotNull(valueWrapper) && ObjectUtil.isNotNull(valueWrapper.get())) { +// return valueWrapper.get().toString(); +// } + Object valueWrapper = cache.getCacheObject(key); + if (ObjectUtil.isNotNull(valueWrapper) && ObjectUtil.isNotNull(valueWrapper)) { + return valueWrapper.toString(); } return null; } @@ -75,7 +83,8 @@ public void addList(String key, Object value) { List coll = this.getList(key, Object.class); coll.add(value); - cacheManager.getCache(TEMP_CACHE_NAME).put(key, JsonUtils.objToJson(coll)); +// cacheManager.getCache(TEMP_CACHE_NAME).put(key, JsonUtils.objToJson(coll)); + cache.setCacheObject(key, JsonUtils.objToJson(coll)); } @@ -88,7 +97,7 @@ public void removeList(String key, Object value) { List coll = this.getList(key, Object.class); coll.remove(value); - cacheManager.getCache(TEMP_CACHE_NAME).put(key, JsonUtils.objToJson(coll)); +// cacheManager.getCache(TEMP_CACHE_NAME).put(key, JsonUtils.objToJson(coll)); } /** @@ -109,7 +118,7 @@ * 涓存椂淇濆瓨 榛樿5min */ public void tempSave(String key, String value) { - cacheManager.getCache(TEMP_CACHE_NAME).put(key, value); +// cacheManager.getCache(TEMP_CACHE_NAME).put(key, value); } /** @@ -117,17 +126,17 @@ * * @param key */ - public String getTemp(String key) { - Cache.ValueWrapper valueWrapper = cacheManager.getCache(TEMP_CACHE_NAME).get(key); - if (ObjectUtil.isNotNull(valueWrapper) && ObjectUtil.isNotNull(valueWrapper.get())) { - return valueWrapper.get().toString(); - } - return null; - } - - public void removeTemp(String key) { - cacheManager.getCache(TEMP_CACHE_NAME).evict(key); - } +// public String getTemp(String key) { +// Cache.ValueWrapper valueWrapper = cacheManager.getCache(TEMP_CACHE_NAME).get(key); +// if (ObjectUtil.isNotNull(valueWrapper) && ObjectUtil.isNotNull(valueWrapper.get())) { +// return valueWrapper.get().toString(); +// } +// return null; +// } +// +// public void removeTemp(String key) { +// cacheManager.getCache(TEMP_CACHE_NAME).evict(key); +// } } -- Gitblit v1.8.0