CacheConfiguration.java 文件源码

java
阅读 37 收藏 0 点赞 0 评论 0

项目:p2p-webtv 作者:
@Bean
public CacheManager cacheManager(ApplicationProperties applicationProperties) {
  log.debug("Starting Ehcache");
  cacheManager = net.sf.ehcache.CacheManager.create();
  cacheManager.getConfiguration().setMaxBytesLocalHeap(applicationProperties.getCache().getEhcache().getMaxBytesLocalHeap());
  log.debug("Registering Ehcache Metrics gauges");
  Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
  for (EntityType<?> entity : entities) {
    String name = entity.getName();
    if (name == null || entity.getJavaType() != null) {
      name = entity.getJavaType().getName();
    }
    Assert.notNull(name, "entity cannot exist without a identifier");

    net.sf.ehcache.Cache cache = cacheManager.getCache(name);
    if (cache != null) {
      cache.getCacheConfiguration().setTimeToLiveSeconds(applicationProperties.getCache().getTimeToLiveSeconds());
      net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
      cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
    }
  }
  EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
  ehCacheManager.setCacheManager(cacheManager);
  return ehCacheManager;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号