@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -31,14 +31,16 @@ public abstract class AbstractCacheInvoker {
|
||||
|
||||
private CacheErrorHandler errorHandler;
|
||||
|
||||
|
||||
protected AbstractCacheInvoker() {
|
||||
this(new SimpleCacheErrorHandler());
|
||||
}
|
||||
|
||||
protected AbstractCacheInvoker(CacheErrorHandler errorHandler) {
|
||||
Assert.notNull("ErrorHandler must not be null");
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
protected AbstractCacheInvoker() {
|
||||
this(new SimpleCacheErrorHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link CacheErrorHandler} instance to use to handle errors
|
||||
@@ -56,6 +58,7 @@ public abstract class AbstractCacheInvoker {
|
||||
return this.errorHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute {@link Cache#get(Object)} on the specified {@link Cache} and
|
||||
* invoke the error handler if an exception occurs. Return {@code null}
|
||||
@@ -67,9 +70,9 @@ public abstract class AbstractCacheInvoker {
|
||||
try {
|
||||
return cache.get(key);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
getErrorHandler().handleCacheGetError(e, cache, key);
|
||||
return null; // If the exception is handled, return a cache miss
|
||||
catch (RuntimeException ex) {
|
||||
getErrorHandler().handleCacheGetError(ex, cache, key);
|
||||
return null; // If the exception is handled, return a cache miss
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +84,8 @@ public abstract class AbstractCacheInvoker {
|
||||
try {
|
||||
cache.put(key, result);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
getErrorHandler().handleCachePutError(e, cache, key, result);
|
||||
catch (RuntimeException ex) {
|
||||
getErrorHandler().handleCachePutError(ex, cache, key, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +97,8 @@ public abstract class AbstractCacheInvoker {
|
||||
try {
|
||||
cache.evict(key);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
getErrorHandler().handleCacheEvictError(e, cache, key);
|
||||
catch (RuntimeException ex) {
|
||||
getErrorHandler().handleCacheEvictError(ex, cache, key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +110,8 @@ public abstract class AbstractCacheInvoker {
|
||||
try {
|
||||
cache.clear();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
getErrorHandler().handleCacheClearError(e, cache);
|
||||
catch (RuntimeException ex) {
|
||||
getErrorHandler().handleCacheClearError(ex, cache);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -76,13 +76,10 @@ import org.springframework.util.StringUtils;
|
||||
* @since 3.1
|
||||
*/
|
||||
public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
implements InitializingBean, SmartInitializingSingleton, ApplicationContextAware {
|
||||
implements ApplicationContextAware, InitializingBean, SmartInitializingSingleton {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
/**
|
||||
* Cache of CacheOperationMetadata, keyed by {@link CacheOperationCacheKey}.
|
||||
*/
|
||||
private final Map<CacheOperationCacheKey, CacheOperationMetadata> metadataCache =
|
||||
new ConcurrentHashMap<CacheOperationCacheKey, CacheOperationMetadata>(1024);
|
||||
|
||||
@@ -273,7 +270,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
* Return a bean with the specified name and type. Used to resolve services that
|
||||
* are referenced by name in a {@link CacheOperation}.
|
||||
* @param beanName the name of the bean, as defined by the operation
|
||||
* @param expectedType type type for the bean
|
||||
* @param expectedType type for the bean
|
||||
* @return the bean matching that name
|
||||
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
|
||||
* @see CacheOperation#keyGenerator
|
||||
@@ -293,8 +290,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
}
|
||||
|
||||
protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
|
||||
// check whether aspect is enabled
|
||||
// to cope with cases where the AJ is pulled in automatically
|
||||
// Check whether aspect is enabled (to cope with cases where the AJ is pulled in automatically)
|
||||
if (this.initialized) {
|
||||
Class<?> targetClass = getTargetClass(target);
|
||||
Collection<CacheOperation> operations = getCacheOperationSource().getCacheOperations(method, targetClass);
|
||||
@@ -377,7 +373,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
excluded.add(context);
|
||||
}
|
||||
}
|
||||
catch (VariableNotAvailableException e) {
|
||||
catch (VariableNotAvailableException ex) {
|
||||
// Ignoring failure due to missing result, consider the cache put has to proceed
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user