You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.3 KiB
29 lines
1.3 KiB
5 years ago
|
package ${basePackage}.config;
|
||
|
|
||
|
import net.sf.ehcache.CacheManager;
|
||
|
import net.sf.ehcache.config.CacheConfiguration;
|
||
|
import org.springframework.cache.annotation.EnableCaching;
|
||
|
import org.springframework.cache.ehcache.EhCacheCacheManager;
|
||
|
import org.springframework.context.annotation.Bean;
|
||
|
import org.springframework.context.annotation.Configuration;
|
||
|
|
||
|
@Configuration
|
||
|
@EnableCaching
|
||
|
public class CacheConfig {
|
||
|
|
||
|
@Bean(name = "tokenCacheManager")
|
||
|
public EhCacheCacheManager tokenCacheManager() {
|
||
|
EhCacheCacheManager ehCacheCacheManager = new EhCacheCacheManager();
|
||
|
net.sf.ehcache.config.Configuration configuration = new net.sf.ehcache.config.Configuration();
|
||
|
configuration.setMaxBytesLocalHeap("2G");
|
||
|
configuration.setUpdateCheck(false);//设置不检查更新
|
||
|
CacheConfiguration cacheConfiguration = new CacheConfiguration();
|
||
|
cacheConfiguration.setTimeToLiveSeconds(60 * 60);//一个小时有效缓存时间
|
||
|
cacheConfiguration.setTimeToIdleSeconds(30 * 60);//30分钟不使用eternal为true会失效
|
||
|
configuration.addDefaultCache(cacheConfiguration);
|
||
|
CacheManager cacheManager = CacheManager.create(configuration);
|
||
|
ehCacheCacheManager.setCacheManager(cacheManager);
|
||
|
return ehCacheCacheManager;
|
||
|
}
|
||
|
}
|