Java Code Examples for net.sf.ehcache.CacheManager#getEhcache()

The following examples show how to use net.sf.ehcache.CacheManager#getEhcache() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EhCacheSupportTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testEhCacheFactoryBeanWithBlockingCache() {
	EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
	cacheManagerFb.afterPropertiesSet();
	try {
		CacheManager cm = cacheManagerFb.getObject();
		EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
		cacheFb.setCacheManager(cm);
		cacheFb.setCacheName("myCache1");
		cacheFb.setBlocking(true);
		assertEquals(cacheFb.getObjectType(), BlockingCache.class);
		cacheFb.afterPropertiesSet();
		Ehcache myCache1 = cm.getEhcache("myCache1");
		assertTrue(myCache1 instanceof BlockingCache);
	}
	finally {
		cacheManagerFb.destroy();
	}
}
 
Example 2
Source File: EhCacheSupportTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testEhCacheFactoryBeanWithSelfPopulatingCache() {
	EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
	cacheManagerFb.afterPropertiesSet();
	try {
		CacheManager cm = cacheManagerFb.getObject();
		EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
		cacheFb.setCacheManager(cm);
		cacheFb.setCacheName("myCache1");
		cacheFb.setCacheEntryFactory(key -> 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();
	}
}
 
Example 3
Source File: EhCacheSupportTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testEhCacheFactoryBeanWithBlockingCache() {
	EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
	cacheManagerFb.afterPropertiesSet();
	try {
		CacheManager cm = cacheManagerFb.getObject();
		EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
		cacheFb.setCacheManager(cm);
		cacheFb.setCacheName("myCache1");
		cacheFb.setBlocking(true);
		assertEquals(cacheFb.getObjectType(), BlockingCache.class);
		cacheFb.afterPropertiesSet();
		Ehcache myCache1 = cm.getEhcache("myCache1");
		assertTrue(myCache1 instanceof BlockingCache);
	}
	finally {
		cacheManagerFb.destroy();
	}
}
 
Example 4
Source File: EhCacheSupportTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testEhCacheFactoryBeanWithSelfPopulatingCache() {
	EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
	cacheManagerFb.afterPropertiesSet();
	try {
		CacheManager cm = cacheManagerFb.getObject();
		EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
		cacheFb.setCacheManager(cm);
		cacheFb.setCacheName("myCache1");
		cacheFb.setCacheEntryFactory(key -> 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();
	}
}
 
Example 5
Source File: EhCacheSupportTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testEhCacheFactoryBeanWithBlockingCache() throws Exception {
	EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
	cacheManagerFb.afterPropertiesSet();
	try {
		CacheManager cm = cacheManagerFb.getObject();
		EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
		cacheFb.setCacheManager(cm);
		cacheFb.setCacheName("myCache1");
		cacheFb.setBlocking(true);
		assertEquals(cacheFb.getObjectType(), BlockingCache.class);
		cacheFb.afterPropertiesSet();
		Ehcache myCache1 = cm.getEhcache("myCache1");
		assertTrue(myCache1 instanceof BlockingCache);
	}
	finally {
		cacheManagerFb.destroy();
	}
}
 
Example 6
Source File: EhCacheSupportTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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").getValue());
	}
	finally {
		cacheManagerFb.destroy();
	}
}
 
Example 7
Source File: EhcacheCacheStorage.java    From esigate with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Properties properties) {
    String cacheName = Parameters.EHCACHE_CACHE_NAME_PROPERTY.getValue(properties);
    String configurationFileName = Parameters.EHCACHE_CONFIGURATION_FILE_PROPERTY.getValue(properties);
    // Loaded from the Classpath, default will use /ehcache.xml or if not found /ehcache-failsafe.xml
    CacheManager cacheManager = CacheManager.create(configurationFileName);
    Ehcache ehcache = cacheManager.getEhcache(cacheName);
    if (ehcache == null) {
        cacheManager.addCache(cacheName);
        ehcache = cacheManager.getEhcache(cacheName);
    }
    CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties);
    setImpl(new EhcacheHttpCacheStorage(ehcache, cacheConfig));
}
 
Example 8
Source File: DefaultDashboardService.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Required
   public void setCacheManager(CacheManager cacheManager) {
	this.cacheManager = cacheManager;		
	// TODO in spring 3.x you can add CacheEventListener in EhCacheFactoryBean !!!
	Ehcache cache =  cacheManager.getEhcache("entitiesCache");	
	WidgetCacheEventListener listener = new WidgetCacheEventListener();
	listener.setDashboardService(DefaultDashboardService.this);
	cache.getCacheEventNotificationService().registerListener(listener);
}
 
Example 9
Source File: CachingAccessTokenStorage.java    From jerseyoauth2 with MIT License 4 votes vote down vote up
@Inject
public CachingAccessTokenStorage(EntityManagerFactory emf, IConfiguration config, CacheManager cacheManager) {
	this.delegate = new DatabaseAccessTokenStorage(emf, config);
	tokenCache = cacheManager.getEhcache("tokenCache");
	assert(tokenCache!=null);
}