| | |
| | | |
| | | import com.github.benmanes.caffeine.cache.Cache; |
| | | import com.github.benmanes.caffeine.cache.Caffeine; |
| | | import com.se.system.SeSystemApplication; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.cloud.context.config.annotation.RefreshScope; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.security.MessageDigest; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @RefreshScope |
| | | @SuppressWarnings("ALL") |
| | | public class CaffeineUtils { |
| | | static Integer cacheTime; |
| | | |
| | | @Value("${sys.cacheTime}") |
| | | public void setCacheTime(Integer cacheTime) { |
| | | CaffeineUtils.cacheTime = cacheTime; |
| | | } |
| | | |
| | | private static Cache<String, Object> cache; |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(CaffeineUtils.class); |
| | | |
| | | public static void init(Integer cacheTime) { |
| | | public static void init() { |
| | | cache = Caffeine.newBuilder() |
| | | .initialCapacity(16) |
| | | .maximumSize(4096) |
| | | .expireAfterWrite(cacheTime, TimeUnit.MINUTES) |
| | | .expireAfterWrite(60 * 60 * 8, TimeUnit.SECONDS) |
| | | .build(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | public static <T> void putListByKey(String key, List<T> list) { |
| | | if (null != list && list.size() > 0) { |
| | | if (null != list) { |
| | | put(key, list); |
| | | } |
| | | } |