Search in sources :

Example 1 with CacheEntryFactory

use of net.sf.ehcache.constructs.blocking.CacheEntryFactory 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 2 with CacheEntryFactory

use of net.sf.ehcache.constructs.blocking.CacheEntryFactory 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

CacheEntryFactory (net.sf.ehcache.constructs.blocking.CacheEntryFactory)2 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)2 CacheException (net.sf.ehcache.CacheException)1 CacheManager (net.sf.ehcache.CacheManager)1 Ehcache (net.sf.ehcache.Ehcache)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