Skip to content

Commit e2f418a

Browse files
committed
Added "transactionAware" bean property to EhCacheCacheManager and JCacheCacheManager
In the course of this enhancement, the "cache.ehcache" and "cache.jcache" packages moved from spring-context to the spring-context-support module, expecting further transaction-related functionality. Also aligns with the presence of Spring's Quartz support in the spring-context-support module, since Quartz and EHCache are sort of sister projects at Terracotta now. Issue: SPR-9966
1 parent 7d7758b commit e2f418a

File tree

20 files changed

+404
-101
lines changed

20 files changed

+404
-101
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ project('spring-context') {
269269
}
270270
compile("joda-time:joda-time:1.6", optional)
271271
compile("org.jruby:jruby:1.4.0", optional)
272-
compile("javax.cache:cache-api:0.5", optional)
273-
compile("net.sf.ehcache:ehcache-core:2.0.0", optional)
274272
compile("org.slf4j:slf4j-api:1.6.1", optional)
275273
compile("org.codehaus.jsr166-mirror:jsr166:1.7.0", provided)
276274
compile("org.aspectj:aspectjweaver:${aspectjVersion}", optional)
@@ -361,6 +359,8 @@ project('spring-context-support') {
361359
compile(project(":spring-jdbc"), optional) // for Quartz support
362360
compile(project(":spring-tx"), optional) // for Quartz support
363361
compile("org.codehaus.fabric3.api:commonj:1.1.0", optional)
362+
compile("javax.cache:cache-api:0.5", optional)
363+
compile("net.sf.ehcache:ehcache-core:2.0.0", optional)
364364
compile("opensymphony:quartz:1.6.2", optional)
365365
compile("javax.mail:mail:1.4", optional)
366366
compile("velocity:velocity:1.5", optional)

spring-context/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java renamed to spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import net.sf.ehcache.Status;
2424

2525
import org.springframework.cache.Cache;
26-
import org.springframework.cache.support.AbstractCacheManager;
26+
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
2727
import org.springframework.util.Assert;
2828

2929
/**
@@ -33,11 +33,27 @@
3333
* @author Juergen Hoeller
3434
* @since 3.1
3535
*/
36-
public class EhCacheCacheManager extends AbstractCacheManager {
36+
public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManager {
3737

3838
private net.sf.ehcache.CacheManager cacheManager;
3939

4040

41+
/**
42+
* Create a new EhCacheCacheManager, setting the target EhCache CacheManager
43+
* through the {@link #setCacheManager} bean property.
44+
*/
45+
public EhCacheCacheManager() {
46+
}
47+
48+
/**
49+
* Create a new EhCacheCacheManager for the given backing EhCache.
50+
* @param cacheManager the backing EhCache {@link net.sf.ehcache.CacheManager}
51+
*/
52+
public EhCacheCacheManager(net.sf.ehcache.CacheManager cacheManager) {
53+
this.cacheManager = cacheManager;
54+
}
55+
56+
4157
/**
4258
* Set the backing EhCache {@link net.sf.ehcache.CacheManager}.
4359
*/

spring-context/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java renamed to spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
import java.util.Collection;
2020
import java.util.LinkedHashSet;
21-
21+
import javax.cache.CacheManager;
2222
import javax.cache.Status;
2323

2424
import org.springframework.cache.Cache;
25-
import org.springframework.cache.support.AbstractCacheManager;
25+
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
2626
import org.springframework.util.Assert;
2727

2828
/**
@@ -32,13 +32,29 @@
3232
* @author Juergen Hoeller
3333
* @since 3.2
3434
*/
35-
public class JCacheCacheManager extends AbstractCacheManager {
35+
public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager {
3636

3737
private javax.cache.CacheManager cacheManager;
3838

3939
private boolean allowNullValues = true;
4040

4141

42+
/**
43+
* Create a new JCacheCacheManager, setting the target JCache CacheManager
44+
* through the {@link #setCacheManager} bean property.
45+
*/
46+
public JCacheCacheManager() {
47+
}
48+
49+
/**
50+
* Create a new JCacheCacheManager for the given backing JCache.
51+
* @param cacheManager the backing JCache {@link javax.cache.CacheManager}
52+
*/
53+
public JCacheCacheManager(CacheManager cacheManager) {
54+
this.cacheManager = cacheManager;
55+
}
56+
57+
4258
/**
4359
* Set the backing JCache {@link javax.cache.CacheManager}.
4460
*/

spring-context/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java renamed to spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import javax.cache.Caching;
2121

2222
import org.springframework.beans.factory.BeanClassLoaderAware;
23+
import org.springframework.beans.factory.DisposableBean;
2324
import org.springframework.beans.factory.FactoryBean;
2425
import org.springframework.beans.factory.InitializingBean;
2526

@@ -33,7 +34,8 @@
3334
* @see javax.cache.Caching#getCacheManager()
3435
* @see javax.cache.Caching#getCacheManager(String)
3536
*/
36-
public class JCacheManagerFactoryBean implements FactoryBean<CacheManager>, BeanClassLoaderAware, InitializingBean {
37+
public class JCacheManagerFactoryBean
38+
implements FactoryBean<CacheManager>, BeanClassLoaderAware, InitializingBean, DisposableBean {
3739

3840
private String cacheManagerName = Caching.DEFAULT_CACHE_MANAGER_NAME;
3941

@@ -74,4 +76,9 @@ public boolean isSingleton() {
7476
return true;
7577
}
7678

79+
80+
public void destroy() {
81+
this.cacheManager.shutdown();
82+
}
83+
7784
}

0 commit comments

Comments
 (0)