From c3e7e622e26c7c9d0c84e8dad32e289bb96be5b7 Mon Sep 17 00:00:00 2001 From: zhaojun1998 Date: Thu, 2 Jan 2020 14:46:55 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=BC=93=E5=AD=98=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9C=AC=E5=9C=B0=20caffeine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/AbstractFileService.java | 13 +++++++++++-- src/main/resources/application.yml | 19 +------------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/main/java/im/zhaojun/common/service/AbstractFileService.java b/src/main/java/im/zhaojun/common/service/AbstractFileService.java index dff613f..c186b98 100644 --- a/src/main/java/im/zhaojun/common/service/AbstractFileService.java +++ b/src/main/java/im/zhaojun/common/service/AbstractFileService.java @@ -9,6 +9,7 @@ import im.zhaojun.common.model.dto.FileItemDTO; import im.zhaojun.common.model.enums.FileTypeEnum; import im.zhaojun.common.model.enums.StorageTypeEnum; import im.zhaojun.common.util.StringUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.aop.framework.AopContext; import org.springframework.beans.factory.annotation.Value; @@ -22,6 +23,7 @@ import java.util.concurrent.TimeUnit; * @author zhaojun * @date 2019/12/28 19:27 */ +@Slf4j public abstract class AbstractFileService implements FileService { @Value("${zfile.cache.timeout}") @@ -32,8 +34,16 @@ public abstract class AbstractFileService implements FileService { @CreateCache(name = "zfile-cache:") private Cache userCache; + /*** + * 获取指定路径下的文件及文件夹, 默认缓存 60 分钟,每隔 30 分钟刷新一次. + * @param path 文件路径 + * @return 文件及文件夹列表 + * @throws Exception 获取文件列表中出现的异常 + */ @Override - @Cached(name = "zfile-cache:", key = "#path", cacheType = CacheType.LOCAL, condition = "mvel{bean('systemConfigService').enableCache}") + @Cached(name = "zfile-cache:", + key = "args[0]", + cacheType = CacheType.LOCAL, condition = "mvel{bean('systemConfigService').enableCache}") @CacheRefresh(refresh = 30, timeUnit = TimeUnit.MINUTES) public abstract List fileList(String path) throws Exception; @@ -42,7 +52,6 @@ public abstract class AbstractFileService implements FileService { * 清理当前存储引擎的缓存 */ public void clearCache() { - } /** diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 92bd11b..808d422 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -13,9 +13,6 @@ server: max-threads: 20 spring: - cache: - type: caffeine -# type: redis datasource: # 初始化数据导入 data: classpath*:db/data.sql @@ -61,18 +58,4 @@ jetcache: default: type: caffeine keyConvertor: fastjson - defaultExpireInMillis: 6000000 - remote: - default: - type: redis - keyConvertor: fastjson - valueEncoder: kryo - valueDecoder: kryo - defaultExpireInMillis: 3600000 - poolConfig: - minIdle: 5 - maxIdle: 20 - maxTotal: 50 - host: 127.0.0.1 - port: 6379 - password: 12345 \ No newline at end of file + defaultExpireInMillis: 3600000 \ No newline at end of file