Search in sources :

Example 71 with Element

use of net.sf.ehcache.Element in project metrics by dropwizard.

the class InstrumentedEhcacheTest method measuresGetsAndPuts.

@Test
public void measuresGetsAndPuts() throws Exception {
    cache.get("woo");
    cache.put(new Element("woo", "whee"));
    final Timer gets = registry.timer(name(Cache.class, "test", "gets"));
    assertThat(gets.getCount()).isEqualTo(1);
    final Timer puts = registry.timer(name(Cache.class, "test", "puts"));
    assertThat(puts.getCount()).isEqualTo(1);
}
Also used : Timer(com.codahale.metrics.Timer) Element(net.sf.ehcache.Element) Cache(net.sf.ehcache.Cache) Test(org.junit.Test)

Example 72 with Element

use of net.sf.ehcache.Element in project gocd by gocd.

the class GoCache method getWithoutTransactionCheck.

private Object getWithoutTransactionCheck(String key) {
    Element element = ehCache.get(key);
    if (element == null) {
        return null;
    }
    Object value = element.getObjectValue();
    logUnsavedPersistentObjectInteraction(value, "PersistentObject %s without an id served out of cache.");
    return value;
}
Also used : Element(net.sf.ehcache.Element) PersistentObject(com.thoughtworks.go.domain.PersistentObject)

Example 73 with Element

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

the class EhcacheGeneralDataRegion method put.

@Override
public void put(SharedSessionContractImplementor session, Object key, Object value) throws CacheException {
    LOG.debugf("key: %s value: %s", key, value);
    try {
        final Element element = new Element(key, value);
        getCache().put(element);
    } catch (IllegalArgumentException e) {
        throw new CacheException(e);
    } catch (IllegalStateException e) {
        throw new CacheException(e);
    } catch (net.sf.ehcache.CacheException e) {
        if (e instanceof NonStopCacheException) {
            HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e);
        } else {
            throw new CacheException(e);
        }
    }
}
Also used : CacheException(org.hibernate.cache.CacheException) NonStopCacheException(net.sf.ehcache.constructs.nonstop.NonStopCacheException) Element(net.sf.ehcache.Element) NonStopCacheException(net.sf.ehcache.constructs.nonstop.NonStopCacheException)

Example 74 with Element

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

the class EhcacheTransactionalDataRegion method put.

/**
	 * Map the given value to the given key, replacing any existing mapping for this key
	 *
	 * @param key The cache key
	 * @param value The data to cache
	 *
	 * @throws CacheException Indicates a problem accessing the cache
	 */
public final void put(Object key, Object value) throws CacheException {
    try {
        final Element element = new Element(key, value);
        getCache().put(element);
    } catch (IllegalArgumentException e) {
        throw new CacheException(e);
    } catch (IllegalStateException e) {
        throw new CacheException(e);
    } catch (net.sf.ehcache.CacheException e) {
        if (e instanceof NonStopCacheException) {
            HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e);
        } else {
            throw new CacheException(e);
        }
    }
}
Also used : NonStopCacheException(net.sf.ehcache.constructs.nonstop.NonStopCacheException) CacheException(org.hibernate.cache.CacheException) Element(net.sf.ehcache.Element) NonStopCacheException(net.sf.ehcache.constructs.nonstop.NonStopCacheException)

Example 75 with Element

use of net.sf.ehcache.Element in project ninja by ninjaframework.

the class CacheEhCacheImpl method replace.

public void replace(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)

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