コード例 #1
0
  @Bean
  public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager
        .getConfiguration()
        .setMaxBytesLocalHeap(
            env.getProperty("cache.ehcache.maxBytesLocalHeap", String.class, "16M"));
    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(env.getProperty("cache.timeToLiveSeconds", Long.class, 3600L));
        net.sf.ehcache.Ehcache decoratedCache =
            InstrumentedEhcache.instrument(metricRegistry, cache);
        cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
      }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
  }
コード例 #2
0
 private void reconfigureCache(String name, JHipsterProperties jHipsterProperties) {
   net.sf.ehcache.Cache cache = cacheManager.getCache(name);
   if (cache != null) {
     cache
         .getCacheConfiguration()
         .setTimeToLiveSeconds(jHipsterProperties.getCache().getTimeToLiveSeconds());
     net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
     cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
   }
 }
コード例 #3
0
 /** @see com.dianping.cache.core.Lifecycle#start() */
 @Override
 public void start() {
   Ehcache cache = manager.getCache(TEMPLATE_CACHE_NAME);
   defaultBlockingCache = new LooseBlockingCache(cache);
   manager.replaceCacheWithDecoratedCache(cache, defaultBlockingCache);
 }