Browse Source

Added note on EhCache 2.1+ as recommended version

pull/231/merge
Juergen Hoeller 12 years ago
parent
commit
6fc0790c5f
  1. 29
      spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java
  2. 31
      spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java

29
spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java vendored

@ -1,5 +1,5 @@ @@ -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.
@ -40,9 +40,9 @@ import org.springframework.beans.factory.InitializingBean; @@ -40,9 +40,9 @@ import org.springframework.beans.factory.InitializingBean;
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
@ -52,7 +52,8 @@ import org.springframework.util.Assert; @@ -52,7 +52,8 @@ import org.springframework.util.Assert;
* <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
@ -117,7 +118,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -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
*/
@ -152,7 +153,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -152,7 +153,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
/**
* 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) {
@ -239,9 +240,9 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -239,9 +240,9 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
}
/**
* 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},
@ -257,7 +258,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -257,7 +258,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
}
/**
* 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) {
@ -265,7 +266,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -265,7 +266,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
}
/**
* 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) {
@ -305,7 +306,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -305,7 +306,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
// 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();
}
@ -320,13 +321,13 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -320,13 +321,13 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
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);
@ -359,7 +360,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -359,7 +360,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
* 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,

31
spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java vendored

@ -35,19 +35,20 @@ import org.springframework.util.ClassUtils; @@ -35,19 +35,20 @@ import org.springframework.util.ClassUtils;
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
@ -59,7 +60,7 @@ import org.springframework.util.ReflectionUtils; @@ -59,7 +60,7 @@ import org.springframework.util.ReflectionUtils;
*/
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);
@ -75,9 +76,9 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini @@ -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)
*/
@ -86,7 +87,7 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini @@ -86,7 +87,7 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini
}
/**
* 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()
@ -97,7 +98,7 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini @@ -97,7 +98,7 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini
}
/**
* 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) {
@ -106,14 +107,14 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini @@ -106,14 +107,14 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini
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);
@ -160,7 +161,7 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini @@ -160,7 +161,7 @@ public class EhCacheManagerFactoryBean implements FactoryBean<CacheManager>, Ini
public void destroy() {
logger.info("Shutting down EHCache CacheManager");
logger.info("Shutting down EhCache CacheManager");
this.cacheManager.shutdown();
}

Loading…
Cancel
Save