Search in sources :

Example 1 with UpdatingCacheEntryFactory

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

the class EhCacheSupportTests method testEhCacheFactoryBeanWithUpdatingSelfPopulatingCache.

@Test
public void testEhCacheFactoryBeanWithUpdatingSelfPopulatingCache() 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 UpdatingCacheEntryFactory() {

            @Override
            public Object createEntry(Object key) throws Exception {
                return key;
            }

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

Aggregations

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 Test (org.junit.Test)1