()
| 35 | } |
| 36 | |
| 37 | @Bean(destroyMethod = "close") |
| 38 | public javax.cache.CacheManager jCacheManager() { |
| 39 | //配置默认缓存属性 |
| 40 | XmlConfiguration xmlConfig = new XmlConfiguration(getClass().getResource("/ehcache.xml")); |
| 41 | EhcacheCachingProvider provider = (EhcacheCachingProvider) Caching.getCachingProvider(); |
| 42 | javax.cache.CacheManager jCache = provider.getCacheManager(provider.getDefaultURI(), xmlConfig); |
| 43 | |
| 44 | //管理员 - 刷新令牌 |
| 45 | Long refreshToken = environment.getProperty("bbs.admin.refreshToken-expiration", Long.class, 2592000L); |
| 46 | javax.cache.configuration.Configuration<Object, Object> configuration_refreshToken = |
| 47 | Eh107Configuration.fromEhcacheCacheConfiguration( |
| 48 | CacheConfigurationBuilder.newCacheConfigurationBuilder( |
| 49 | Object.class, |
| 50 | Object.class, |
| 51 | ResourcePoolsBuilder.heap(99999999)) |
| 52 | .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(java.time.Duration.of(refreshToken, ChronoUnit.SECONDS))) |
| 53 | .build() |
| 54 | ); |
| 55 | if (jCache.getCache("adminCacheManager_cache_refreshToken", Object.class, Object.class) != null) { |
| 56 | jCache.destroyCache("adminCacheManager_cache_refreshToken"); |
| 57 | } |
| 58 | jCache.createCache("adminCacheManager_cache_refreshToken", configuration_refreshToken); |
| 59 | |
| 60 | //管理员 - 访问令牌 |
| 61 | Long accessToken = environment.getProperty("bbs.admin.accessToken-expiration", Long.class, 7200L); |
| 62 | javax.cache.configuration.Configuration<Object, Object> configuration_accessToken = |
| 63 | Eh107Configuration.fromEhcacheCacheConfiguration( |
| 64 | CacheConfigurationBuilder.newCacheConfigurationBuilder( |
| 65 | Object.class, |
| 66 | Object.class, |
| 67 | ResourcePoolsBuilder.heap(99999999)) |
| 68 | .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(java.time.Duration.of(accessToken, ChronoUnit.SECONDS))) |
| 69 | .build() |
| 70 | ); |
| 71 | if (jCache.getCache("adminCacheManager_cache_accessToken", Object.class, Object.class) != null) { |
| 72 | jCache.destroyCache("adminCacheManager_cache_accessToken"); |
| 73 | } |
| 74 | jCache.createCache("adminCacheManager_cache_accessToken", configuration_accessToken); |
| 75 | |
| 76 | return jCache; |
| 77 | } |
| 78 | } |
no test coverage detected