소스 검색

fix:用户map 10小时刷新一次缓存

wangbo 2 년 전
부모
커밋
ceb7d28062
1개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      smsb-customer-manager-app/src/main/java/com/inspur/customer/service/keycloak/KeycloakServiceImpl.java

+ 14 - 0
smsb-customer-manager-app/src/main/java/com/inspur/customer/service/keycloak/KeycloakServiceImpl.java

@@ -16,11 +16,14 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.keycloak.admin.client.resource.*;
 import org.keycloak.representations.idm.*;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
@@ -46,6 +49,17 @@ public class KeycloakServiceImpl implements KeycloakService {
         return userMap;
     }
 
+    @CacheEvict(value = "smsb:users" , allEntries = true)
+    public void clearUserMapCache(){
+        log.info("users map cache clear:{}",LocalDateTime.now() );
+    }
+
+    @Scheduled(cron = "* * 0/10 * * ?")
+    public void expiredCache(){
+        // 每隔10小时,清除缓存数据初始化一次
+        this.clearUserMapCache();
+    }
+
     /**
      * get users in role (xuzhou environment)
      * @param role role