and support Cache instance create by CacheManager.getOrCreateCache
@@ -49,23 +49,27 @@ public class CacheContext {
private Cache createOrGetCache(CacheInvokeContext invokeContext, CacheAnnoConfig cacheAnnoConfig, ConfigMap configMap) {
Cache cache = cacheAnnoConfig.getCache();
- if (cache == null) {
+ if (cache != null) {
+ return cache;
+ }
if (cacheAnnoConfig instanceof CachedAnnoConfig) {
cache = createCacheByCachedConfig((CachedAnnoConfig) cacheAnnoConfig, invokeContext);
} else if ((cacheAnnoConfig instanceof CacheInvalidateAnnoConfig) || (cacheAnnoConfig instanceof CacheUpdateAnnoConfig)) {
+ cache = cacheManager.getCache(cacheAnnoConfig.getArea(), cacheAnnoConfig.getName());
+ if (cache == null) {
CachedAnnoConfig cac = configMap.getByCacheName(cacheAnnoConfig.getArea(), cacheAnnoConfig.getName());
if (cac == null) {
- String message = "can't find @Cached definition with area=" + cacheAnnoConfig.getArea()
+ String message = "can't find cache definition with area=" + cacheAnnoConfig.getArea()
+ " name=" + cacheAnnoConfig.getName() +
", specified in " + cacheAnnoConfig.getDefineMethod();
CacheConfigException e = new CacheConfigException(message);
- logger.error("Cache operation aborted because can't find @Cached definition", e);
+ logger.error("Cache operation aborted because can't find cached definition", e);
return null;
}
cache = createCacheByCachedConfig(cac, invokeContext);
}
- cacheAnnoConfig.setCache(cache);
}
+ cacheAnnoConfig.setCache(cache);
return cache;
}
