Search in sources :

Example 6 with Element

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;
}
Also used : Element(net.sf.ehcache.Element)

Example 7 with Element

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;
}
Also used : Element(net.sf.ehcache.Element)

Example 8 with Element

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);
}
Also used : Element(net.sf.ehcache.Element)

Example 9 with 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);
    }
}
Also used : CacheException(net.sf.ehcache.CacheException) Element(net.sf.ehcache.Element) Cache(net.sf.ehcache.Cache)

Example 10 with Element

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;
}
Also used : Element(net.sf.ehcache.Element)

Aggregations

Element (net.sf.ehcache.Element)114 Test (org.junit.Test)21 CacheKey (org.apereo.portal.utils.cache.CacheKey)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cache (net.sf.ehcache.Cache)7 HashSet (java.util.HashSet)6 CacheException (net.sf.ehcache.CacheException)6 MalformedURLException (java.net.MalformedURLException)5 ConfigurationException (javax.naming.ConfigurationException)5 Ehcache (net.sf.ehcache.Ehcache)5 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)5 EntityIdentifier (org.apereo.portal.EntityIdentifier)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URISyntaxException (java.net.URISyntaxException)4 SQLException (java.sql.SQLException)4 EntityExistsException (javax.persistence.EntityExistsException)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 BaseCacheTest (org.apache.camel.component.BaseCacheTest)4