Search in sources :

Example 11 with Element

use of net.sf.ehcache.Element in project spring-framework by spring-projects.

the class EhCacheCacheTests method testExpiredElements.

@Test
public void testExpiredElements() throws Exception {
    Assume.group(TestGroup.LONG_RUNNING);
    String key = "brancusi";
    String value = "constantin";
    Element brancusi = new Element(key, value);
    // ttl = 10s
    brancusi.setTimeToLive(3);
    nativeCache.put(brancusi);
    assertEquals(value, cache.get(key).get());
    // wait for the entry to expire
    Thread.sleep(5 * 1000);
    assertNull(cache.get(key));
}
Also used : Element(net.sf.ehcache.Element) Test(org.junit.Test)

Example 12 with Element

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

the class EhCacheBasedCacheController method putIfAbsent.

public void putIfAbsent(final K key, V value) {
    final Element element = new Element(key, value);
    cache.putIfAbsent(element);
}
Also used : Element(net.sf.ehcache.Element)

Example 13 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedUserCache method putUserInCache.

public void putUserInCache(UserDetails user) {
    Element element = new Element(user.getUsername(), user);
    if (logger.isDebugEnabled()) {
        logger.debug("Cache put: " + element.getKey());
    }
    cache.put(element);
}
Also used : Element(net.sf.ehcache.Element)

Example 14 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method evictCacheObjectIdentity.

@Test
public void evictCacheObjectIdentity() throws Exception {
    when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl));
    myCache.evictFromCache(acl.getId());
    verify(cache).remove(acl.getId());
    verify(cache).remove(acl.getObjectIdentity());
}
Also used : Element(net.sf.ehcache.Element) Test(org.junit.Test)

Example 15 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method getFromCacheSerializable.

@Test
public void getFromCacheSerializable() throws Exception {
    when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl));
    assertThat(myCache.getFromCache(acl.getId())).isEqualTo(acl);
}
Also used : Element(net.sf.ehcache.Element) Test(org.junit.Test)

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