Skip to content

Commit

Permalink
Added note on EhCache 2.1+ as recommended version
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Feb 11, 2013
1 parent cef9781 commit 6fc0790
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,9 +40,9 @@
import org.springframework.util.Assert;

/**
* {@link FactoryBean} that creates a named EHCache {@link net.sf.ehcache.Cache} instance
* {@link FactoryBean} that creates a named EhCache {@link net.sf.ehcache.Cache} instance
* (or a decorator that implements the {@link net.sf.ehcache.Ehcache} interface),
* representing a cache region within an EHCache {@link net.sf.ehcache.CacheManager}.
* representing a cache region within an EhCache {@link net.sf.ehcache.CacheManager}.
*
* <p>If the specified named cache is not configured in the cache configuration descriptor,
* this FactoryBean will construct an instance of a Cache with the provided name and the
Expand All @@ -52,7 +52,8 @@
* <p>Note: If the named Cache instance is found, the properties will be ignored and the
* Cache instance will be retrieved from the CacheManager.
*
* <p>Note: As of Spring 3.0, Spring's EHCache support requires EHCache 1.3 or higher.
* <p>Note: As of Spring 3.0, Spring's EhCache support requires EhCache 1.3 or higher.
* As of Spring 3.2, we recommend using EhCache 2.1 or higher.
* @author Dmitriy Kopylenko
* @author Juergen Hoeller
Expand Down Expand Up @@ -117,7 +118,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
* properly handle the shutdown of the CacheManager: Set up a separate
* EhCacheManagerFactoryBean and pass a reference to this bean property.
* <p>A separate EhCacheManagerFactoryBean is also necessary for loading
* EHCache configuration from a non-default config location.
* EhCache configuration from a non-default config location.
* @see EhCacheManagerFactoryBean
* @see net.sf.ehcache.CacheManager#getInstance
*/
Expand Down Expand Up @@ -152,7 +153,7 @@ public void setMaxElementsOnDisk(int maxElementsOnDisk) {
/**
* Set the memory style eviction policy for this cache.
* <p>Supported values are "LRU", "LFU" and "FIFO", according to the
* constants defined in EHCache's MemoryStoreEvictionPolicy class.
* constants defined in EhCache's MemoryStoreEvictionPolicy class.
* Default is "LRU".
*/
public void setMemoryStoreEvictionPolicy(MemoryStoreEvictionPolicy memoryStoreEvictionPolicy) {
Expand Down Expand Up @@ -239,9 +240,9 @@ public void setBlocking(boolean blocking) {
}

/**
* Set an EHCache {@link net.sf.ehcache.constructs.blocking.CacheEntryFactory}
* Set an EhCache {@link net.sf.ehcache.constructs.blocking.CacheEntryFactory}
* to use for a self-populating cache. If such a factory is specified,
* the cache will be decorated with EHCache's
* the cache will be decorated with EhCache's
* {@link net.sf.ehcache.constructs.blocking.SelfPopulatingCache}.
* <p>The specified factory can be of type
* {@link net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory},
Expand All @@ -257,15 +258,15 @@ public void setCacheEntryFactory(CacheEntryFactory cacheEntryFactory) {
}

/**
* Set an EHCache {@link net.sf.ehcache.bootstrap.BootstrapCacheLoader}
* Set an EhCache {@link net.sf.ehcache.bootstrap.BootstrapCacheLoader}
* for this cache, if any.
*/
public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader) {
this.bootstrapCacheLoader = bootstrapCacheLoader;
}

/**
* Specify EHCache {@link net.sf.ehcache.event.CacheEventListener cache event listeners}
* Specify EhCache {@link net.sf.ehcache.event.CacheEventListener cache event listeners}
* to registered with this cache.
*/
public void setCacheEventListeners(Set<CacheEventListener> cacheEventListeners) {
Expand Down Expand Up @@ -305,7 +306,7 @@ public void afterPropertiesSet() throws CacheException, IOException {
// If no CacheManager given, fetch the default.
if (this.cacheManager == null) {
if (logger.isDebugEnabled()) {
logger.debug("Using default EHCache CacheManager for cache region '" + this.cacheName + "'");
logger.debug("Using default EhCache CacheManager for cache region '" + this.cacheName + "'");
}
this.cacheManager = CacheManager.getInstance();
}
Expand All @@ -320,13 +321,13 @@ public void afterPropertiesSet() throws CacheException, IOException {
Ehcache rawCache;
if (this.cacheManager.cacheExists(this.cacheName)) {
if (logger.isDebugEnabled()) {
logger.debug("Using existing EHCache cache region '" + this.cacheName + "'");
logger.debug("Using existing EhCache cache region '" + this.cacheName + "'");
}
rawCache = this.cacheManager.getEhcache(this.cacheName);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Creating new EHCache cache region '" + this.cacheName + "'");
logger.debug("Creating new EhCache cache region '" + this.cacheName + "'");
}
rawCache = createCache();
this.cacheManager.addCache(rawCache);
Expand Down Expand Up @@ -359,7 +360,7 @@ public void afterPropertiesSet() throws CacheException, IOException {
* Create a raw Cache object based on the configuration of this FactoryBean.
*/
protected Cache createCache() {
// Only call EHCache 1.6 constructor if actually necessary (for compatibility with EHCache 1.3+)
// Only call EhCache 1.6 constructor if actually necessary (for compatibility with EhCache 1.3+)
return (!this.clearOnFlush) ?
new Cache(this.cacheName, this.maxElementsInMemory, this.memoryStoreEvictionPolicy,
this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@
import org.springframework.util.ReflectionUtils;

/**
* {@link FactoryBean} that exposes an EHCache {@link net.sf.ehcache.CacheManager}
* {@link FactoryBean} that exposes an EhCache {@link net.sf.ehcache.CacheManager}
* instance (independent or shared), configured from a specified config location.
*
* <p>If no config location is specified, a CacheManager will be configured from
* "ehcache.xml" in the root of the class path (that is, default EHCache initialization
* - as defined in the EHCache docs - will apply).
* "ehcache.xml" in the root of the class path (that is, default EhCache initialization
* - as defined in the EhCache docs - will apply).
*
* <p>Setting up a separate EhCacheManagerFactoryBean is also advisable when using
* EhCacheFactoryBean, as it provides a (by default) independent CacheManager instance
* and cares for proper shutdown of the CacheManager. EhCacheManagerFactoryBean is
* also necessary for loading EHCache configuration from a non-default config location.
* also necessary for loading EhCache configuration from a non-default config location.
*
* <p>Note: As of Spring 3.0, Spring's EHCache support requires EHCache 1.3 or higher.
* <p>Note: As of Spring 3.0, Spring's EhCache support requires EhCache 1.3 or higher.
* As of Spring 3.2, we recommend using EhCache 2.1 or higher.
*
* @author Dmitriy Kopylenko
* @author Juergen Hoeller
Expand All @@ -59,7 +60,7 @@
*/
public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, InitializingBean, DisposableBean {

// Check whether EHCache 2.1+ CacheManager.create(Configuration) method is available...
// Check whether EhCache 2.1+ CacheManager.create(Configuration) method is available...
private static final Method createWithConfiguration =
ClassUtils.getMethodIfAvailable(CacheManager.class, "create", Configuration.class);

Expand All @@ -75,9 +76,9 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini


/**
* Set the location of the EHCache config file. A typical value is "/WEB-INF/ehcache.xml".
* Set the location of the EhCache config file. A typical value is "/WEB-INF/ehcache.xml".
* <p>Default is "ehcache.xml" in the root of the class path, or if not found,
* "ehcache-failsafe.xml" in the EHCache jar (default EHCache initialization).
* "ehcache-failsafe.xml" in the EhCache jar (default EhCache initialization).
* @see net.sf.ehcache.CacheManager#create(java.io.InputStream)
* @see net.sf.ehcache.CacheManager#CacheManager(java.io.InputStream)
*/
Expand All @@ -86,7 +87,7 @@ public void setConfigLocation(Resource configLocation) {
}

/**
* Set whether the EHCache CacheManager should be shared (as a singleton at the VM level)
* Set whether the EhCache CacheManager should be shared (as a singleton at the VM level)
* or independent (typically local within the application). Default is "false", creating
* an independent instance.
* @see net.sf.ehcache.CacheManager#create()
Expand All @@ -97,7 +98,7 @@ public void setShared(boolean shared) {
}

/**
* Set the name of the EHCache CacheManager (if a specific name is desired).
* Set the name of the EhCache CacheManager (if a specific name is desired).
* @see net.sf.ehcache.CacheManager#setName(String)
*/
public void setCacheManagerName(String cacheManagerName) {
Expand All @@ -106,14 +107,14 @@ public void setCacheManagerName(String cacheManagerName) {


public void afterPropertiesSet() throws IOException, CacheException {
logger.info("Initializing EHCache CacheManager");
logger.info("Initializing EhCache CacheManager");
InputStream is = (this.configLocation != null ? this.configLocation.getInputStream() : null);
try {
// A bit convoluted for EHCache 1.x/2.0 compatibility.
// To be much simpler once we require EHCache 2.1+
// A bit convoluted for EhCache 1.x/2.0 compatibility.
// To be much simpler once we require EhCache 2.1+
if (this.cacheManagerName != null) {
if (this.shared && createWithConfiguration == null) {
// No CacheManager.create(Configuration) method available before EHCache 2.1;
// No CacheManager.create(Configuration) method available before EhCache 2.1;
// can only set CacheManager name after creation.
this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
this.cacheManager.setName(this.cacheManagerName);
Expand Down Expand Up @@ -160,7 +161,7 @@ public boolean isSingleton() {


public void destroy() {
logger.info("Shutting down EHCache CacheManager");
logger.info("Shutting down EhCache CacheManager");
this.cacheManager.shutdown();
}

Expand Down

0 comments on commit 6fc0790

Please sign in to comment.