Search in sources :

Example 81 with Element

use of net.sf.ehcache.Element in project JMPjct by MPjct.

the class Eh method read_query_result.

public void read_query_result(Engine context) {
    if (Eh.cache == null)
        return;
    // Cache this key?
    if (this.TTL == 0 || context.buffer.size() == 0)
        return;
    Element element = new Element(this.key, context.buffer);
    element.setTimeToLive(this.TTL);
    Eh.cache.put(element);
    Eh.cache.releaseWriteLockOnKey(this.key);
}
Also used : Element(net.sf.ehcache.Element)

Example 82 with Element

use of net.sf.ehcache.Element in project jforum2 by rafaelsteil.

the class EhCacheEngine method add.

public void add(String fullyQualifiedName, String key, Object value) {
    if (!manager.cacheExists(fullyQualifiedName)) {
        try {
            manager.addCache(fullyQualifiedName);
        } catch (CacheException ce) {
            log.error(ce, ce);
            throw new RuntimeException(ce);
        }
    }
    Cache cache = manager.getCache(fullyQualifiedName);
    Element element = new Element(key, (Serializable) value);
    cache.put(element);
}
Also used : CacheException(net.sf.ehcache.CacheException) Element(net.sf.ehcache.Element) Cache(net.sf.ehcache.Cache)

Example 83 with Element

use of net.sf.ehcache.Element in project CloudStack-archive by CloudStack-extras.

the class GenericDaoBase method toVO.

@DB(txn = false)
protected T toVO(ResultSet result, boolean cache) throws SQLException {
    T entity;
    try {
        entity = _entityBeanType.newInstance();
    } catch (InstantiationException e1) {
        throw new CloudRuntimeException("Unable to instantiate entity", e1);
    } catch (IllegalAccessException e1) {
        throw new CloudRuntimeException("Illegal Access", e1);
    }
    toEntityBean(result, entity);
    if (cache && _cache != null) {
        try {
            _cache.put(new Element(_idField.get(entity), entity));
        } catch (final Exception e) {
            s_logger.debug("Can't put it in the cache", e);
        }
    }
    return entity;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Element(net.sf.ehcache.Element) URISyntaxException(java.net.URISyntaxException) EntityExistsException(javax.persistence.EntityExistsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException)

Example 84 with Element

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

the class EhCacheBasedAclCacheTests method getFromCacheSerializablePopulatesTransient.

@Test
public void getFromCacheSerializablePopulatesTransient() throws Exception {
    when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl));
    myCache.putInCache(acl);
    ReflectionTestUtils.setField(acl, "permissionGrantingStrategy", null);
    ReflectionTestUtils.setField(acl, "aclAuthorizationStrategy", null);
    MutableAcl fromCache = myCache.getFromCache(acl.getId());
    assertThat(ReflectionTestUtils.getField(fromCache, "aclAuthorizationStrategy")).isNotNull();
    assertThat(ReflectionTestUtils.getField(fromCache, "permissionGrantingStrategy")).isNotNull();
}
Also used : Element(net.sf.ehcache.Element) MutableAcl(org.springframework.security.acls.model.MutableAcl) Test(org.junit.Test)

Example 85 with Element

use of net.sf.ehcache.Element in project ORCID-Source by ORCID.

the class ProfileEntityCacheManagerImpl method retrieve.

@Override
@Transactional
public ProfileEntity retrieve(String orcid) throws IllegalArgumentException {
    Object key = new OrcidCacheKey(orcid, releaseName);
    Date dbDate = profileEntityManager.getLastModifiedDate(orcid);
    ProfileEntity profile = toProfileEntity(profileCache.get(key));
    if (needsFresh(dbDate, profile))
        try {
            synchronized (lockers.obtainLock(orcid)) {
                profile = toProfileEntity(profileCache.get(key));
                if (needsFresh(dbDate, profile)) {
                    profile = profileEntityManager.findByOrcid(orcid);
                    if (profile == null)
                        throw new IllegalArgumentException("Invalid orcid " + orcid);
                    if (profile.getGivenPermissionBy() != null) {
                        profile.getGivenPermissionBy().size();
                    }
                    if (profile.getGivenPermissionTo() != null) {
                        profile.getGivenPermissionTo().size();
                    }
                    profileCache.put(new Element(key, profile));
                }
            }
        } finally {
            lockers.releaseLock(orcid);
        }
    return profile;
}
Also used : Element(net.sf.ehcache.Element) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

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