瀏覽代碼

树形结构缓存

gaodm 5 年之前
父節點
當前提交
9dbd1935f6

+ 6 - 0
config-server/src/main/resources/shared/ltkg-service-dev.yml

@@ -37,6 +37,12 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200
+
 #mybatis
 mybatis:
   type-aliases-package: com.diagbot.entity

+ 6 - 0
config-server/src/main/resources/shared/ltkg-service-local.yml

@@ -37,6 +37,12 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200
+
 #mybatis
 mybatis:
   type-aliases-package: com.diagbot.entity

+ 6 - 0
config-server/src/main/resources/shared/ltkg-service-pre.yml

@@ -37,6 +37,12 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200
+
 #mybatis
 mybatis:
   type-aliases-package: com.diagbot.entity

+ 6 - 0
config-server/src/main/resources/shared/ltkg-service-pro.yml

@@ -37,6 +37,12 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200
+
 #mybatis
 mybatis:
   type-aliases-package: com.diagbot.entity

+ 6 - 0
config-server/src/main/resources/shared/ltkg-service-test.yml

@@ -37,6 +37,12 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200
+
 #mybatis
 mybatis:
   type-aliases-package: com.diagbot.entity

+ 8 - 9
ltkg-service/src/main/java/com/diagbot/web/KgController.java

@@ -16,6 +16,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -58,7 +59,9 @@ public class KgController {
     @ApiOperation(value = "获取树形分类", notes = "获取树形分类")
     @PostMapping("/getTree")
     @SysLogger("getTree")
+    @Cacheable(value = KGTREECACHE, key = "'kgtree:t_' + #kgTreeVO.type + '_st_' + #kgTreeVO.subType")
     public RespDTO<String> getTree(@RequestBody @Valid KgTreeVO kgTreeVO) {
+        log.info("获取树形分类缓存成功");
         return RespDTO.onSuc(kgFacade.getTreeFac(kgTreeVO));
     }
 
@@ -77,18 +80,14 @@ public class KgController {
         return RespDTO.onSuc(kgFacade.getTuFac(kgQueryVO));
     }
 
-    /**
-     * 清理权限所有缓存
-     *
-     * @return
-     */
-    @ApiOperation(value = "获取树形分类缓存", notes = "获取树形分类缓存")
+
+    @ApiOperation(value = "清理树形分类缓存", notes = "清理树形分类缓存")
     @PostMapping("/delKgTreeCache")
     @SysLogger("delKgTreeCache")
     @CacheEvict(cacheNames = KGTREECACHE, allEntries = true)
-    public Boolean delKgTreeCache() {
-        log.info("清理服务权限缓存成功");
-        return true;
+    public RespDTO<Boolean> delKgTreeCache() {
+        log.info("清理树形分类缓存成功");
+        return RespDTO.onSuc(true);
     }
 }