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();
}
}
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;
}
}
});
}
Aggregations