Example usage for org.springframework.cache.jcache JCacheCacheManager JCacheCacheManager

List of usage examples for org.springframework.cache.jcache JCacheCacheManager JCacheCacheManager

Introduction

In this page you can find the example usage for org.springframework.cache.jcache JCacheCacheManager JCacheCacheManager.

Prototype

public JCacheCacheManager(CacheManager cacheManager) 

Source Link

Document

Create a new JCacheCacheManager for the given backing JCache CacheManager javax.cache.CacheManager .

Usage

From source file:cz.muni.fi.editor.services.commons.CacheManagerFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    CachingProvider provider = Caching.getCachingProvider();

    javax.cache.CacheManager cacheManager = provider.getCacheManager(
            getClass().getResource("/config/cache.xml").toURI(), provider.getDefaultClassLoader());
    MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>();
    configuration.setStoreByValue(false);

    /**/*from w  w  w  .  j  ava2s  .c om*/
     * avoids dirties context reset of cache, where cache already exists
     */
    for (String s : new String[] { "userCache", "organizationCache", "organizationCacheList" }) {
        if (cacheManager.getCache(s) == null) {
            cacheManager.createCache(s, configuration);
        }
    }

    this.cacheManager = new JCacheCacheManager(cacheManager);
}

From source file:org.drugis.addis.config.MainConfig.java

@Bean
public CacheManager cacheManager() {
    long numberOfCacheItems = 100;
    long fourHours = 60 * 60 * 4;

    CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Object.class, Object.class,
                    ResourcePoolsBuilder.heap(numberOfCacheItems))
            .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(fourHours))).build();

    Map<String, CacheConfiguration<?, ?>> caches = createCacheConfigurations(cacheConfiguration);

    EhcacheCachingProvider provider = (EhcacheCachingProvider) Caching.getCachingProvider();
    DefaultConfiguration configuration = new DefaultConfiguration(caches, provider.getDefaultClassLoader());
    return new JCacheCacheManager(provider.getCacheManager(provider.getDefaultURI(), configuration));
}