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