Просмотр исходного кода

ICSS和DATA缓存启动初始化

gaodm 5 лет назад
Родитель
Сommit
509d51e2c6

+ 3 - 1
data-service/src/main/java/com/diagbot/facade/CacheFacade.java

@@ -1,6 +1,7 @@
 package com.diagbot.facade;
 
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Component;
 
 /**
@@ -16,7 +17,8 @@ public class CacheFacade {
      *
      * @return
      */
-    @CacheEvict(value = "data-service", allEntries = true)
+    @Caching(evict = { @CacheEvict(value = "data-service", allEntries = true),
+            @CacheEvict(value = "aipt-service", allEntries = true) })
     public void clear() {
 
     }

+ 29 - 0
icss-service/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: zhoutg
+ * @time: 2020/4/3 14:31
+ */
+@Component //把类交给spring容器管理
+@Order(100)  //使用order属性,设置该类在spring容器中的加载顺序
+@Slf4j
+public class CacheDeleteInit implements CommandLineRunner {
+
+    @Autowired
+    CacheFacade cacheFacade;
+
+    @Override
+    public void run(String... args) throws Exception {
+        // 服务启动清除redis缓存
+        log.info("ICSS嵌入模式缓存启动初始化成功!");
+        cacheFacade.clear();
+    }
+}

+ 26 - 0
icss-service/src/main/java/com/diagbot/facade/CacheFacade.java

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