org.springframework.cache.jcache.JCacheCacheManager Java Examples
The following examples show how to use
org.springframework.cache.jcache.JCacheCacheManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Application.java From conciliator with GNU General Public License v3.0 | 5 votes |
@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)); }
Example #2
Source File: CacheConfiguration.java From ehcache3-samples with Apache License 2.0 | 4 votes |
@Bean @Override public org.springframework.cache.CacheManager cacheManager() { return new JCacheCacheManager(environment.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION) ? createClusteredCacheManager() : createInMemoryCacheManager()); }