net.sf.ehcache.constructs.blocking.BlockingCache Java Examples

The following examples show how to use net.sf.ehcache.constructs.blocking.BlockingCache. 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: EhCacheFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Predict the particular {@code Ehcache} implementation that will be returned from
 * {@link #getObject()} based on logic in {@link #createCache()} and
 * {@link #decorateCache(Ehcache)} as orchestrated by {@link #afterPropertiesSet()}.
 */
@Override
public Class<? extends Ehcache> getObjectType() {
	if (this.cache != null) {
		return this.cache.getClass();
	}
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return UpdatingSelfPopulatingCache.class;
		}
		else {
			return SelfPopulatingCache.class;
		}
	}
	if (this.blocking) {
		return BlockingCache.class;
	}
	return Cache.class;
}
 
Example #2
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 #3
Source File: EhCacheFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Predict the particular {@code Ehcache} implementation that will be returned from
 * {@link #getObject()} based on logic in {@link #createCache()} and
 * {@link #decorateCache(Ehcache)} as orchestrated by {@link #afterPropertiesSet()}.
 */
@Override
public Class<? extends Ehcache> getObjectType() {
	if (this.cache != null) {
		return this.cache.getClass();
	}
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return UpdatingSelfPopulatingCache.class;
		}
		else {
			return SelfPopulatingCache.class;
		}
	}
	if (this.blocking) {
		return BlockingCache.class;
	}
	return Cache.class;
}
 
Example #4
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 #5
Source File: EhCacheFactoryBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Predict the particular {@code Ehcache} implementation that will be returned from
 * {@link #getObject()} based on logic in {@link #createCache()} and
 * {@link #decorateCache(Ehcache)} as orchestrated by {@link #afterPropertiesSet()}.
 */
@Override
public Class<? extends Ehcache> getObjectType() {
	if (this.cache != null) {
		return this.cache.getClass();
	}
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return UpdatingSelfPopulatingCache.class;
		}
		else {
			return SelfPopulatingCache.class;
		}
	}
	if (this.blocking) {
		return BlockingCache.class;
	}
	return Cache.class;
}
 
Example #6
Source File: EhCacheFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Predict the particular {@code Ehcache} implementation that will be returned from
 * {@link #getObject()} based on logic in {@link #createCache()} and
 * {@link #decorateCache(Ehcache)} as orchestrated by {@link #afterPropertiesSet()}.
 */
@Override
public Class<? extends Ehcache> getObjectType() {
	if (this.cache != null) {
		return this.cache.getClass();
	}
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return UpdatingSelfPopulatingCache.class;
		}
		else {
			return SelfPopulatingCache.class;
		}
	}
	if (this.blocking) {
		return BlockingCache.class;
	}
	return Cache.class;
}
 
Example #7
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 #8
Source File: EhCacheFactory.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
protected void createCache(String name, int expirationTime) {
		synchronized (this.getClass()) {
			cacheManager.addCache(name);

			Ehcache cache = cacheManager.getEhcache(name);
			CacheConfiguration config = cache.getCacheConfiguration();
			config.setEternal(false);
			config.setTimeToLiveSeconds(expirationTime);
//		    config.setTimeToIdleSeconds(60);
//		    config.setMaxElementsInMemory(10000);
//		    config.setMaxElementsOnDisk(1000000);
		    
			BlockingCache blockingCache = new BlockingCache(cache);
			cacheManager.replaceCacheWithDecoratedCache(cache, blockingCache);
		}
	}
 
Example #9
Source File: EhCacheFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Decorate the given Cache, if necessary.
 * @param cache the raw Cache object, based on the configuration of this FactoryBean
 * @return the (potentially decorated) cache object to be registered with the CacheManager
 */
protected Ehcache decorateCache(Ehcache cache) {
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory);
		}
		else {
			return new SelfPopulatingCache(cache, this.cacheEntryFactory);
		}
	}
	if (this.blocking) {
		return new BlockingCache(cache);
	}
	return cache;
}
 
Example #10
Source File: EhCacheFactoryBean.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Decorate the given Cache, if necessary.
 * @param cache the raw Cache object, based on the configuration of this FactoryBean
 * @return the (potentially decorated) cache object to be registered with the CacheManager
 */
protected Ehcache decorateCache(Ehcache cache) {
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory);
		}
		else {
			return new SelfPopulatingCache(cache, this.cacheEntryFactory);
		}
	}
	if (this.blocking) {
		return new BlockingCache(cache);
	}
	return cache;
}
 
Example #11
Source File: EhCacheFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decorate the given Cache, if necessary.
 * @param cache the raw Cache object, based on the configuration of this FactoryBean
 * @return the (potentially decorated) cache object to be registered with the CacheManager
 */
protected Ehcache decorateCache(Ehcache cache) {
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory);
		}
		else {
			return new SelfPopulatingCache(cache, this.cacheEntryFactory);
		}
	}
	if (this.blocking) {
		return new BlockingCache(cache);
	}
	return cache;
}
 
Example #12
Source File: EhCacheFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Decorate the given Cache, if necessary.
 * @param cache the raw Cache object, based on the configuration of this FactoryBean
 * @return the (potentially decorated) cache object to be registered with the CacheManager
 */
protected Ehcache decorateCache(Ehcache cache) {
	if (this.cacheEntryFactory != null) {
		if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
			return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory);
		}
		else {
			return new SelfPopulatingCache(cache, this.cacheEntryFactory);
		}
	}
	if (this.blocking) {
		return new BlockingCache(cache);
	}
	return cache;
}
 
Example #13
Source File: EhCacheFacade.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Decorate the given Cache, if necessary.
 * <p>The default implementation simply returns the given cache object as-is.
 *
 * @param cache the raw Cache object, based on the configuration of this FactoryBean
 * @param model the model containing the name of the cache to retrieve
 * @return the (potentially decorated) cache object to be registered with the CacheManager
 */
protected Ehcache decorateCache(Cache cache, EhCacheCachingModel model) {
	if (model.getCacheEntryFactory() != null) {
		if (model.getCacheEntryFactory() instanceof UpdatingCacheEntryFactory) {
			return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) model.getCacheEntryFactory());
		} else {
			return new SelfPopulatingCache(cache, model.getCacheEntryFactory());
		}
	}
	if (model.isBlocking()) {
		return new BlockingCache(cache);
	}
	return cache;
}
 
Example #14
Source File: CacheFactory.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Create and return a reference to {@link Cache} object.
 *
 * @return instance of {@link Cache}.
 */
public static Cache createInstance(String name, net.sf.ehcache.CacheManager cacheManager)
{
    net.sf.ehcache.Ehcache cache = cacheManager.getEhcache(name);
    if(cache == null)
    {
        String error = "createInstance cache: " + name + " is null";
        throw new CfgRuntimeException(GlobalErrIds.FT_CACHE_NOT_CONFIGURED, error);
    }
    BlockingCache blockingCache = new BlockingCache(cache);
    blockingCache.setTimeoutMillis(60000);
    
    cacheManager.replaceCacheWithDecoratedCache(cache, blockingCache);
    return new EhCacheImpl(name, blockingCache);
}
 
Example #15
Source File: CacheMgr.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new reference to the ehcache cache implementation.
 *
 * @param cacheName contains the name of the cache to retrieve
 * @return reference to cache for specified object.
 */
public Cache getCache( String cacheName )
{    	
    Ehcache cache = mEhCacheImpl.getEhcache( cacheName );
    if(cache != null)
    {
	    return new EhCacheImpl( cacheName, new BlockingCache(cache) );
    }
    else
    {
	    return CacheFactory.createInstance( cacheName, mEhCacheImpl );
    }
}
 
Example #16
Source File: EhCacheImpl.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Create an instance of a wrapped, singleton cache instance using Ehcache.
 *
 * @param name name for the cache instance.
 * @param blockingCache that is being wrapped.
 */
EhCacheImpl( String name, BlockingCache blockingCache )
{
    this.name = name;
    if ( blockingCache == null )
    {
        String error = " constructor cache: " + name + " is null";
        throw new CfgRuntimeException( GlobalErrIds.FT_CACHE_NOT_CONFIGURED, error );
    }
    this.cache = blockingCache;
}