类org.springframework.cache.jcache.JCacheCacheManager源码实例Demo

下面列出了怎么用org.springframework.cache.jcache.JCacheCacheManager的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: conciliator   文件: Application.java
@Bean
public CacheManager cacheManager(@Autowired Config config) {
    long ttl = Long.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_TTL));

    config.getProperties().getProperty(Config.PROP_CACHE_SIZE);

    MemSize memSize = MemSize.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_SIZE));

    LogFactory.getLog(getClass()).info(
            String.format("Initializing cache TTL=%d secs, size=%d %s",
                    ttl, memSize.getSize(), memSize.getUnit().toString()));

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Object.class, Object.class,
                    ResourcePoolsBuilder.newResourcePoolsBuilder()
                            .heap(memSize.getSize(), memSize.getUnit()))
            .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
            .build();

    Map<String, CacheConfiguration<?, ?>> caches = new HashMap<>();
    caches.put(CACHE_DEFAULT, cacheConfiguration);

    EhcacheCachingProvider provider = (EhcacheCachingProvider) javax.cache.Caching.getCachingProvider();

    // when our cacheManager bean is re-created several times for
    // diff test configurations, this provider seems to hang on to state
    // causing cache settings to not be right. so we always close().
    provider.close();

    DefaultConfiguration configuration = new DefaultConfiguration(
            caches, provider.getDefaultClassLoader());

    return new JCacheCacheManager(
            provider.getCacheManager(provider.getDefaultURI(), configuration));
}
 
源代码2 项目: ehcache3-samples   文件: CacheConfiguration.java
@Bean
@Override
public org.springframework.cache.CacheManager cacheManager() {
    return new JCacheCacheManager(environment.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION) ?
        createClusteredCacheManager() : createInMemoryCacheManager());
}
 
 类方法
 同包方法