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 --------------