Search in sources :

Example 36 with Element

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

the class OrcidProfileCacheManagerImpl method retrievePublic.

@Override
public OrcidProfile retrievePublic(String orcid) {
    Object key = new OrcidCacheKey(orcid, releaseName);
    Date dbDate = retrieveLastModifiedDate(orcid);
    OrcidProfile op = toOrcidProfile(publicProfileCache.get(key));
    if (needsFresh(dbDate, op))
        try {
            synchronized (pubLocks.obtainLock(orcid)) {
                op = toOrcidProfile(publicProfileCache.get(orcid));
                if (needsFresh(dbDate, op)) {
                    op = orcidProfileManager.retrievePublicOrcidProfile(orcid);
                    publicProfileCache.put(new Element(key, op));
                }
            }
        } finally {
            pubLocks.releaseLock(orcid);
        }
    return op;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Element(net.sf.ehcache.Element) Date(java.util.Date)

Example 37 with Element

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

the class OrcidProfileCacheManagerImpl method retrieve.

@Override
public OrcidProfile retrieve(String orcid) {
    Object key = new OrcidCacheKey(orcid, releaseName);
    Date dbDate = retrieveLastModifiedDate(orcid);
    OrcidProfile op = toOrcidProfile(profileCache.get(key));
    if (needsFresh(dbDate, op))
        try {
            synchronized (profileLockers.obtainLock(orcid)) {
                op = toOrcidProfile(profileCache.get(orcid));
                if (needsFresh(dbDate, op)) {
                    op = orcidProfileManager.retrieveFreshOrcidProfile(orcid, LoadOptions.ALL);
                    profileCache.put(new Element(key, op));
                }
            }
        } finally {
            profileLockers.releaseLock(orcid);
        }
    return op;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Element(net.sf.ehcache.Element) Date(java.util.Date)

Example 38 with Element

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

the class GenericDaoBase method toEntityBean.

@SuppressWarnings("unchecked")
@DB(txn = false)
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
    final T entity = (T) _factory.newInstance(new Callback[] { NoOp.INSTANCE, new UpdateBuilder(this) });
    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 : Callback(net.sf.cglib.proxy.Callback) 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 39 with Element

use of net.sf.ehcache.Element in project cloudstack by apache.

the class GenericDaoBase method toEntityBean.

@SuppressWarnings("unchecked")
@DB()
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
    final T entity = (T) _factory.newInstance(new Callback[] { NoOp.INSTANCE, new UpdateBuilder(this) });
    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 : Callback(net.sf.cglib.proxy.Callback) 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 40 with Element

use of net.sf.ehcache.Element in project cloudstack by apache.

the class IAMServiceImpl method addToIAMCache.

@Override
public void addToIAMCache(Object accessKey, Object allowDeny) {
    if (_iamCache != null) {
        try {
            s_logger.debug("Put IAM access check for " + accessKey + " in cache");
            _iamCache.put(new Element(accessKey, allowDeny));
        } catch (final Exception e) {
            s_logger.debug("Can't put " + accessKey + " to IAM cache", e);
        }
    }
}
Also used : Element(net.sf.ehcache.Element) ConfigurationException(javax.naming.ConfigurationException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

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