Search in sources :

Example 1 with SelfPopulatingCache

use of net.sf.ehcache.constructs.blocking.SelfPopulatingCache in project ORCID-Source by ORCID.

the class OrcidEhCacheFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    Ehcache existingCache = cacheManager.getEhcache(cacheName);
    String diskStorePath = cacheManager.getConfiguration().getDiskStoreConfiguration().getPath();
    LOGGER.debug("Cache manager disk store path = " + diskStorePath);
    if (existingCache == null) {
        CacheConfiguration config = createConfig();
        if (cacheEntryFactory != null) {
            this.cache = new SelfPopulatingCache(new Cache(config), cacheEntryFactory);
        } else {
            this.cache = new Cache(config);
        }
        cacheManager.addCache(this.cache);
    } else {
        this.cache = existingCache;
    }
}
Also used : SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Ehcache(net.sf.ehcache.Ehcache) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Cache(net.sf.ehcache.Cache)

Example 2 with SelfPopulatingCache

use of net.sf.ehcache.constructs.blocking.SelfPopulatingCache in project spring-framework by spring-projects.

the class EhCacheSupportTests method testEhCacheFactoryBeanWithSelfPopulatingCache.

@Test
public void testEhCacheFactoryBeanWithSelfPopulatingCache() throws Exception {
    EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
    cacheManagerFb.afterPropertiesSet();
    try {
        CacheManager cm = cacheManagerFb.getObject();
        EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
        cacheFb.setCacheManager(cm);
        cacheFb.setCacheName("myCache1");
        cacheFb.setCacheEntryFactory(new CacheEntryFactory() {

            @Override
            public Object createEntry(Object key) throws Exception {
                return key;
            }
        });
        assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class);
        cacheFb.afterPropertiesSet();
        Ehcache myCache1 = cm.getEhcache("myCache1");
        assertTrue(myCache1 instanceof SelfPopulatingCache);
        assertEquals("myKey1", myCache1.get("myKey1").getObjectValue());
    } finally {
        cacheManagerFb.destroy();
    }
}
Also used : SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) UpdatingSelfPopulatingCache(net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache) UpdatingCacheEntryFactory(net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory) CacheEntryFactory(net.sf.ehcache.constructs.blocking.CacheEntryFactory) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) CacheException(net.sf.ehcache.CacheException) Test(org.junit.Test)

Example 3 with SelfPopulatingCache

use of net.sf.ehcache.constructs.blocking.SelfPopulatingCache in project uPortal by Jasig.

the class FragmentActivator method setUserViews.

@Autowired
public void setUserViews(@Qualifier("org.apereo.portal.layout.dlm.FragmentActivator.userViews") Ehcache userViews) {
    this.userViews = new SelfPopulatingCache(userViews, new CacheEntryFactory() {

        @Override
        public Object createEntry(Object key) throws Exception {
            final UserViewKey userViewKey = (UserViewKey) key;
            // Check if there was an exception the last time a load attempt was
            // made and re-throw
            final net.sf.ehcache.Element exceptionElement = userViewErrors.get(userViewKey);
            if (exceptionElement != null) {
                throw (Exception) exceptionElement.getObjectValue();
            }
            try {
                return activateFragment(userViewKey);
            } catch (Exception e) {
                userViewErrors.put(new net.sf.ehcache.Element(userViewKey, e));
                throw e;
            }
        }
    });
}
Also used : SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) CacheEntryFactory(net.sf.ehcache.constructs.blocking.CacheEntryFactory) Element(org.w3c.dom.Element) AuthorizationException(org.apereo.portal.AuthorizationException) Autowired(org.springframework.beans.factory.annotation.Autowired)

Aggregations

SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)3 Ehcache (net.sf.ehcache.Ehcache)2 CacheEntryFactory (net.sf.ehcache.constructs.blocking.CacheEntryFactory)2 Cache (net.sf.ehcache.Cache)1 CacheException (net.sf.ehcache.CacheException)1 CacheManager (net.sf.ehcache.CacheManager)1 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)1 UpdatingCacheEntryFactory (net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory)1 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)1 AuthorizationException (org.apereo.portal.AuthorizationException)1 Test (org.junit.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Element (org.w3c.dom.Element)1