package com.zcloud.util; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import com.zcloud.entity.PageData; import com.zcloud.mapper.datasource.system.DictionariesMapper; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; /** * 说明:缓存 * 作者:wangxuan * 官网:www.zcloudchina.com */ @Component public class CaffeineUtil { private static final Logger logger = Logger.getLogger(CaffeineUtil.class.getName()); /** * @Description: 登录token * @Author: dearLin * @Date: 2023/6/12/012 9:27 * @Param: [] [] * @Return: com.github.benmanes.caffeine.cache.Cache */ @Bean(name = "loginToken") public Cache loginToken() { Cache loginToken = Caffeine.newBuilder() // 30分钟 .expireAfterAccess(30, TimeUnit.MINUTES) // 当垃圾收集器需要释放内存时驱逐 .softValues() .removalListener(((key, value, cause) -> { //清理通知 key,value ==> 键值对 cause ==> 清理原因 System.out.printf("Key %s was removed (%s)%n", key, cause); })).build(); return loginToken; } }