zhoutg 4 éve
szülő
commit
3ab0d7b44c

+ 29 - 0
src/main/java/com/diagbot/config/CacheDeleteInit.java

@@ -0,0 +1,29 @@
+package com.diagbot.config;
+
+import com.diagbot.facade.CacheFacade;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description: 项目启动后初始化缓存
+ * @author: gaodm
+ * @time: 2020/5/13 11:20
+ */
+@Component //把类交给spring容器管理
+@Order(100)  //使用order属性,设置该类在spring容器中的加载顺序
+@Slf4j
+public class CacheDeleteInit implements CommandLineRunner {
+
+    @Autowired
+    CacheFacade cacheFacade;
+
+    @Override
+    public void run(String... args) throws Exception {
+        // 服务启动清除redis缓存
+        cacheFacade.clear();
+        log.info("CDSS-CORE服务启动清除redis缓存成功!");
+    }
+}

+ 23 - 0
src/main/java/com/diagbot/facade/CacheFacade.java

@@ -0,0 +1,23 @@
+package com.diagbot.facade;
+
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description:
+ * @Author:zhoutg
+ * @time: 2018/11/23 11:37
+ */
+@Component
+public class CacheFacade {
+
+    /**
+     * 清除缓存信息
+     *
+     * @return
+     */
+    @CacheEvict(value = "cache", allEntries = true)
+    public void clear() {
+
+    }
+}

+ 2 - 1
src/main/java/com/diagbot/facade/NeoFacade.java

@@ -5,6 +5,7 @@ import com.diagbot.vo.BillNeoVO;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -35,7 +36,7 @@ public class NeoFacade {
     @Cacheable(value = "cache", key = "'drugCache'")
     public Map<String, List<String>> getDrugCache() {
         Map<String, List<String>> res = new HashMap<>();
-
+        res.put("ddd", new ArrayList<>());
         return res;
     }
 }

+ 39 - 0
src/main/java/com/diagbot/web/CacheController.java

@@ -0,0 +1,39 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.CacheFacade;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 缓存 前端控制器
+ * </p>
+ *
+ * @author zhoutg
+ * @since 2018-12-25
+ */
+@RequestMapping("/cache")
+@RestController
+@SuppressWarnings("unchecked")
+@Api(value = "缓存API", tags = { "缓存API" })
+public class CacheController {
+
+
+    @Autowired
+    CacheFacade cacheFacade;
+
+    @ApiOperation(value = "清除缓存[by:zhoutg]",
+            notes = "")
+    @PostMapping("/clear")
+    @SysLogger("clear")
+    public RespDTO<Boolean> clear() {
+        cacheFacade.clear();
+        return RespDTO.onSuc(true);
+    }
+}