Search in sources :

Example 51 with CacheManager

use of net.sf.ehcache.CacheManager in project cosmic by MissionCriticalCloud.

the class GenericDaoBase method createCache.

@DB()
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 52 with CacheManager

use of net.sf.ehcache.CacheManager in project cosmic by MissionCriticalCloud.

the class ApiRateLimitServiceImpl method configure.

@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    super.configure(name, params);
    if (_store == null) {
        // get global configured duration and max values
        final String isEnabled = _configDao.getValue(Config.ApiLimitEnabled.key());
        if (isEnabled != null) {
            enabled = Boolean.parseBoolean(isEnabled);
        }
        final String duration = _configDao.getValue(Config.ApiLimitInterval.key());
        if (duration != null) {
            timeToLive = Integer.parseInt(duration);
        }
        final String maxReqs = _configDao.getValue(Config.ApiLimitMax.key());
        if (maxReqs != null) {
            maxAllowed = Integer.parseInt(maxReqs);
        }
        // create limit store
        final EhcacheLimitStore cacheStore = new EhcacheLimitStore();
        int maxElements = 10000;
        final String cachesize = _configDao.getValue(Config.ApiLimitCacheSize.key());
        if (cachesize != null) {
            maxElements = Integer.parseInt(cachesize);
        }
        final CacheManager cm = CacheManager.create();
        final Cache cache = new Cache("api-limit-cache", maxElements, false, false, timeToLive, timeToLive);
        cm.addCache(cache);
        s_logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements);
        cacheStore.setCache(cache);
        _store = cacheStore;
    }
    return true;
}
Also used : CacheManager(net.sf.ehcache.CacheManager) Cache(net.sf.ehcache.Cache)

Example 53 with CacheManager

use of net.sf.ehcache.CacheManager in project oc-explorer by devgateway.

the class MarkupCacheService method clearReportsCache.

/**
 * Remove from cache all reports content
 */
public void clearReportsCache() {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsCache");
    if (cache != null) {
        cache.removeAll();
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Example 54 with CacheManager

use of net.sf.ehcache.CacheManager in project oc-explorer by devgateway.

the class MarkupCacheService method getReportsStat.

/**
 * Display some statistics about reports cache
 */
public void getReportsStat() {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsCache");
    @SuppressWarnings("unchecked") List<String> cacheKeys = cache.getKeys();
    long size = 0;
    for (String k : cacheKeys) {
        logger.info("key: " + k);
        byte[] buf = (byte[]) cache.get(k).getObjectValue();
        size += buf.length;
    }
    Statistics stats = cache.getStatistics();
    StringBuffer sb = new StringBuffer();
    sb.append(String.format("%s objects, %s hits, %s misses\n", stats.getObjectCount(), stats.getCacheHits(), stats.getCacheMisses()));
    logger.info(String.valueOf(sb));
    logger.info("cache total size: " + FileUtils.byteCountToDisplaySize(size));
}
Also used : CacheManager(net.sf.ehcache.CacheManager) Statistics(net.sf.ehcache.Statistics) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Example 55 with CacheManager

use of net.sf.ehcache.CacheManager in project oc-explorer by devgateway.

the class MarkupCacheService method addReportToCache.

/**
 * Add the content of a report (PDF, Excel, RTF) to cache
 *
 * @param outputType
 * @param reportName
 * @param parameters
 * @param buffer
 */
public void addReportToCache(final String outputType, final String reportName, final String parameters, final byte[] buffer) {
    CacheManager cm = CacheManager.getInstance();
    // get the reports cache "reportsCache", declared in ehcache.xml
    Cache cache = cm.getCache("reportsCache");
    cache.put(new Element(createCacheKey(outputType, reportName, parameters), buffer));
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) MarkupCache(org.apache.wicket.markup.MarkupCache) Cache(net.sf.ehcache.Cache)

Aggregations

CacheManager (net.sf.ehcache.CacheManager)102 Cache (net.sf.ehcache.Cache)55 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Element (net.sf.ehcache.Element)20 Configuration (net.sf.ehcache.config.Configuration)18 Test (org.junit.Test)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)17 MarkupCache (org.apache.wicket.markup.MarkupCache)10 CacheException (net.sf.ehcache.CacheException)9 IOException (java.io.IOException)7 Ehcache (net.sf.ehcache.Ehcache)7 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 URL (java.net.URL)5 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)5 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)4 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)4 Around (org.aspectj.lang.annotation.Around)4 Before (org.junit.Before)4 File (java.io.File)3