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;
}
}
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;
}
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();
}
}
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));
}
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));
}
Aggregations