use of net.sf.ehcache.Element in project ninja by ninjaframework.
the class CacheEhCacheImpl method decr.
public synchronized long decr(String key, int by) {
Element e = ehCache.get(key);
if (e == null) {
return -1;
}
long newValue = ((Number) e.getObjectValue()).longValue() - by;
Element newE = new Element(key, newValue);
newE.setTimeToLive(e.getTimeToLive());
ehCache.put(newE);
return newValue;
}
use of net.sf.ehcache.Element in project ninja by ninjaframework.
the class CacheEhCacheImpl method incr.
public synchronized long incr(String key, int by) {
Element e = ehCache.get(key);
if (e == null) {
return -1;
}
long newValue = ((Number) e.getObjectValue()).longValue() + by;
Element newE = new Element(key, newValue);
newE.setTimeToLive(e.getTimeToLive());
ehCache.put(newE);
return newValue;
}
use of net.sf.ehcache.Element in project ninja by ninjaframework.
the class CacheEhCacheImpl method add.
public void add(String key, Object value, int expiration) {
if (ehCache.get(key) != null) {
return;
}
Element element = new Element(key, value);
element.setTimeToLive(expiration);
ehCache.put(element);
}
use of net.sf.ehcache.Element in project jforum2 by rafaelsteil.
the class EhCacheEngine method get.
public Object get(String fullyQualifiedName, String key) {
try {
if (!manager.cacheExists(fullyQualifiedName)) {
manager.addCache(fullyQualifiedName);
return null;
}
Cache cache = manager.getCache(fullyQualifiedName);
Element element = cache.get(key);
if (element != null) {
return element.getValue();
}
return null;
} catch (CacheException ce) {
log.error("EhCache could not be shutdown", ce);
throw new RuntimeException(ce);
}
}
use of net.sf.ehcache.Element in project spring-framework by spring-projects.
the class EhCacheCache method get.
@Override
@SuppressWarnings("unchecked")
public <T> T get(Object key, Class<T> type) {
Element element = this.cache.get(key);
Object value = (element != null ? element.getObjectValue() : null);
if (value != null && type != null && !type.isInstance(value)) {
throw new IllegalStateException("Cached value is not of required type [" + type.getName() + "]: " + value);
}
return (T) value;
}
Aggregations