Search in sources :

Example 1 with Cache

use of net.sf.ehcache.Cache in project hibernate-orm by hibernate.

the class EhcacheStatsImpl method getRegionCacheSamples.

@Override
public Map<String, int[]> getRegionCacheSamples() {
    final Map<String, int[]> rv = new HashMap<String, int[]>();
    for (String name : cacheManager.getCacheNames()) {
        final Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            final Double hits = cache.getStatistics().cacheHitOperation().rate().value();
            final Double misses = cache.getStatistics().cacheMissNotFoundOperation().rate().value();
            final Double expired = cache.getStatistics().cacheMissExpiredOperation().rate().value();
            final Double puts = cache.getStatistics().cachePutOperation().rate().value();
            rv.put(name, new int[] { hits.intValue(), misses.intValue(), expired.intValue(), puts.intValue() });
        }
    }
    return rv;
}
Also used : HashMap(java.util.HashMap) Cache(net.sf.ehcache.Cache)

Example 2 with Cache

use of net.sf.ehcache.Cache in project hibernate-orm by hibernate.

the class EhcacheStatsImpl method setRegionCacheTargetMaxInMemoryCount.

@Override
public void setRegionCacheTargetMaxInMemoryCount(String region, int targetMaxInMemoryCount) {
    final Cache cache = this.cacheManager.getCache(region);
    if (cache != null) {
        cache.getCacheConfiguration().setMaxElementsInMemory(targetMaxInMemoryCount);
        sendNotification(CACHE_REGION_CHANGED, getRegionCacheAttributes(region), region);
    }
}
Also used : Cache(net.sf.ehcache.Cache)

Example 3 with Cache

use of net.sf.ehcache.Cache in project hibernate-orm by hibernate.

the class EhcacheStatsImpl method setRegionCacheTargetMaxTotalCount.

@Override
public void setRegionCacheTargetMaxTotalCount(String region, int targetMaxTotalCount) {
    final Cache cache = this.cacheManager.getCache(region);
    if (cache != null) {
        cache.getCacheConfiguration().setMaxElementsOnDisk(targetMaxTotalCount);
        sendNotification(CACHE_REGION_CHANGED, getRegionCacheAttributes(region), region);
    }
}
Also used : Cache(net.sf.ehcache.Cache)

Example 4 with Cache

use of net.sf.ehcache.Cache in project CloudStack-archive by CloudStack-extras.

the class GenericDaoBase method createCache.

@DB(txn = false)
protected void createCache(final Map<String, ? extends Object> params) {
    final String value = (String) params.get("cache.size");
    if (value != null) {
        final CacheManager cm = CacheManager.create();
        final int maxElements = NumbersUtil.parseInt(value, 0);
        final int live = NumbersUtil.parseInt((String) params.get("cache.time.to.live"), 300);
        final int idle = NumbersUtil.parseInt((String) params.get("cache.time.to.idle"), 300);
        _cache = new Cache(getName(), maxElements, false, live == -1, live == -1 ? Integer.MAX_VALUE : live, idle);
        cm.addCache(_cache);
        s_logger.info("Cache created: " + _cache.toString());
    } else {
        _cache = null;
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) Cache(net.sf.ehcache.Cache)

Example 5 with Cache

use of net.sf.ehcache.Cache in project ORCID-Source by ORCID.

the class OrcidEhCacheFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    Ehcache existingCache = cacheManager.getEhcache(cacheName);
    String diskStorePath = cacheManager.getConfiguration().getDiskStoreConfiguration().getPath();
    LOGGER.debug("Cache manager disk store path = " + diskStorePath);
    if (existingCache == null) {
        CacheConfiguration config = createConfig();
        if (cacheEntryFactory != null) {
            this.cache = new SelfPopulatingCache(new Cache(config), cacheEntryFactory);
        } else {
            this.cache = new Cache(config);
        }
        cacheManager.addCache(this.cache);
    } else {
        this.cache = existingCache;
    }
}
Also used : SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Ehcache(net.sf.ehcache.Ehcache) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Cache(net.sf.ehcache.Cache)

Aggregations

Cache (net.sf.ehcache.Cache)147 CacheManager (net.sf.ehcache.CacheManager)54 Element (net.sf.ehcache.Element)47 ClassPathResource (org.springframework.core.io.ClassPathResource)25 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)24 CacheException (net.sf.ehcache.CacheException)11 MarkupCache (org.apache.wicket.markup.MarkupCache)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Ehcache (net.sf.ehcache.Ehcache)7 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)7 List (java.util.List)6 DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)6 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)6 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 IOException (java.io.IOException)5 Query (net.sf.ehcache.search.Query)5 Results (net.sf.ehcache.search.Results)5 URL (java.net.URL)4 Statistics (net.sf.ehcache.Statistics)4