From dcadffa26595f1ea9b7951a944e4a2e0e77e1b6f Mon Sep 17 00:00:00 2001 From: zhaojun <873019219@qq.com> Date: Sun, 5 Mar 2023 15:24:27 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=A2=9E=E5=8A=A0=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E7=BC=93=E5=AD=98=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84?= =?UTF-8?q?=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhaojun/zfile/core/config/SpringCacheConfig.java | 10 ++++++++-- src/main/resources/application.properties | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/im/zhaojun/zfile/core/config/SpringCacheConfig.java b/src/main/java/im/zhaojun/zfile/core/config/SpringCacheConfig.java index 8d4a437..b1e8cdd 100644 --- a/src/main/java/im/zhaojun/zfile/core/config/SpringCacheConfig.java +++ b/src/main/java/im/zhaojun/zfile/core/config/SpringCacheConfig.java @@ -1,8 +1,11 @@ package im.zhaojun.zfile.core.config; +import cn.hutool.core.util.BooleanUtil; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; +import org.springframework.cache.support.NoOpCacheManager; import org.springframework.cache.transaction.TransactionAwareCacheManagerProxy; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -15,13 +18,16 @@ import org.springframework.context.annotation.Configuration; @Configuration @EnableCaching public class SpringCacheConfig { - + + @Value("${zfile.dbCache.enable:true}") + private Boolean dbCacheEnable; + /** * 使用 TransactionAwareCacheManagerProxy 装饰 ConcurrentMapCacheManager,使其支持事务 (将 put、evict、clear 操作延迟到事务成功提交再执行.) */ @Bean public CacheManager cacheManager() { - return new TransactionAwareCacheManagerProxy(new ConcurrentMapCacheManager()); + return BooleanUtil.isFalse(dbCacheEnable) ? new NoOpCacheManager() : new TransactionAwareCacheManagerProxy(new ConcurrentMapCacheManager()); } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 972b36f..56aa9b7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,6 +7,8 @@ zfile.db.path=${user.home}/.zfile-v4/db/zfile zfile.preview.text.maxFileSizeKb=512 +zfile.dbCache.enable=true + server.port=8080 # -------------- database config start --------------