Пример #1
0
  @Bean
  public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager
        .getConfiguration()
        .setMaxBytesLocalHeap(jHipsterProperties.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(jHipsterProperties.getCache().getTimeToLiveSeconds());
        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
 @PreDestroy
 public void destroy() {
   log.info("Remove Cache Manager metrics");
   SortedSet<String> names = metricRegistry.getNames();
   names.forEach(metricRegistry::remove);
   log.info("Closing Cache Manager");
   cacheManager.shutdown();
 }
Пример #4
0
 @Bean
 public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
   log.debug("Starting Ehcache");
   cacheManager = net.sf.ehcache.CacheManager.create();
   cacheManager
       .getConfiguration()
       .setMaxBytesLocalHeap(jHipsterProperties.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 an identifier");
     reconfigureCache(name, jHipsterProperties);
     for (PluralAttribute pluralAttribute : entity.getPluralAttributes()) {
       reconfigureCache(name + "." + pluralAttribute.getName(), jHipsterProperties);
     }
   }
   EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
   ehCacheManager.setCacheManager(cacheManager);
   return ehCacheManager;
 }