| | |
| | | package com.dy.sso.config; |
| | | |
| | | |
| | | import com.dy.common.util.NumUtil; |
| | | import com.github.benmanes.caffeine.cache.Caffeine; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.cache.CacheManager; |
| | | import org.springframework.cache.caffeine.CaffeineCacheManager; |
| | | import org.springframework.context.annotation.Bean; |
| | |
| | | |
| | | @Configuration |
| | | public class CaffeineCacheConfiguration { |
| | | private static final int cacheInitialCapacityDefault = 10 ; |
| | | private static final int cacheMaximumSizeDefault = 10000 ; |
| | | private static final int cacheDurationDefault = 720 ; |
| | | |
| | | @Value("${pipIrr.sso.cacheMaximumSize}") |
| | | private String cacheMaximumSize ; |
| | | |
| | | @Value("${pipIrr.sso.cacheDuration}") |
| | | private String cacheDuration ; |
| | | /* |
| | | initialCapacity=[integer]: 初始的缓存空间大小 |
| | | maximumSize=[long]: 缓存的最大条数 |
| | |
| | | */ |
| | | @Bean |
| | | public CacheManager cacheManager() { |
| | | int cacheMaximumSizeInt; |
| | | int cacheDurationInt; |
| | | if(NumUtil.isPlusIntNumber(cacheMaximumSize)){ |
| | | cacheMaximumSizeInt = Integer.parseInt(cacheMaximumSize) ; |
| | | }else{ |
| | | cacheMaximumSizeInt = cacheMaximumSizeDefault ; |
| | | } |
| | | if(NumUtil.isPlusIntNumber(cacheDuration)){ |
| | | cacheDurationInt = Integer.parseInt(cacheDuration) ; |
| | | }else{ |
| | | cacheDurationInt = cacheDurationDefault ; |
| | | } |
| | | CaffeineCacheManager cacheManager = new CaffeineCacheManager(); |
| | | cacheManager.setCaffeine(Caffeine.newBuilder() |
| | | .initialCapacity(10) |
| | | .maximumSize(10000) |
| | | .expireAfterAccess(30, TimeUnit.MINUTES)); |
| | | .initialCapacity(cacheInitialCapacityDefault) |
| | | .maximumSize(cacheMaximumSizeInt) |
| | | .expireAfterAccess(cacheDurationInt, TimeUnit.MINUTES)); |
| | | |
| | | return cacheManager; |
| | | } |