Fix cache decoration
Prior to this commit, a cache that is added on-the-fly is not properly decorated by the provided CacheManager implementation that supports it (EhCache and JCache). This commits adds an extra getMissingCache method to the AbstractCacheManager that can be extended to provide a cache that may exist in the native cache manager but is not yet known by the spring abstraction. Issue: SPR-11518
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
* @since 3.1
|
||||
*/
|
||||
public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManager {
|
||||
@@ -86,17 +87,14 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cache getCache(String name) {
|
||||
Cache cache = super.getCache(name);
|
||||
if (cache == null) {
|
||||
// Check the EhCache cache again (in case the cache was added at runtime)
|
||||
Ehcache ehcache = getCacheManager().getEhcache(name);
|
||||
if (ehcache != null) {
|
||||
addCache(new EhCacheCache(ehcache));
|
||||
cache = super.getCache(name); // potentially decorated
|
||||
}
|
||||
protected Cache getMissingCache(String name) {
|
||||
// check the EhCache cache again
|
||||
// (in case the cache was added at runtime)
|
||||
Ehcache ehcache = getCacheManager().getEhcache(name);
|
||||
if (ehcache != null) {
|
||||
return new EhCacheCache(ehcache);
|
||||
}
|
||||
return cache;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.cache.transaction.AbstractTransactionSupportingCacheM
|
||||
* <p>Note: This class has been updated for JCache 1.0, as of Spring 4.0.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
* @since 3.2
|
||||
*/
|
||||
public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager {
|
||||
@@ -108,17 +109,13 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cache getCache(String name) {
|
||||
Cache cache = super.getCache(name);
|
||||
if (cache == null) {
|
||||
// Check the JCache cache again (in case the cache was added at runtime)
|
||||
javax.cache.Cache<Object, Object> jcache = getCacheManager().getCache(name);
|
||||
if (jcache != null) {
|
||||
addCache(new JCacheCache(jcache, isAllowNullValues()));
|
||||
cache = super.getCache(name); // potentially decorated
|
||||
}
|
||||
protected Cache getMissingCache(String name) {
|
||||
// Check the JCache cache again (in case the cache was added at runtime)
|
||||
javax.cache.Cache<Object, Object> jcache = getCacheManager().getCache(name);
|
||||
if (jcache != null) {
|
||||
return new JCacheCache(jcache, isAllowNullValues());
|
||||
}
|
||||
return cache;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user