+ add target object to KeyGenerator
This commit is contained in:
Costin Leau 2011-03-28 18:09:04 +00:00
parent 71d70a6e06
commit 5c3ceb8ef0
3 changed files with 5 additions and 3 deletions

View File

@ -26,5 +26,5 @@ import java.lang.reflect.Method;
*/
public interface KeyGenerator<K> {
K extract(Method method, Object... params);
K extract(Object target, Method method, Object... params);
}

View File

@ -306,6 +306,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
private CacheDefinition definition;
private final Collection<Cache<?, ?>> caches;
private final Object target;
private final Method method;
private final Object[] args;
@ -318,6 +319,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
Object target, Class<?> targetClass) {
this.definition = operationDefinition;
this.caches = CacheAspectSupport.this.getCaches(definition);
this.target = target;
this.method = method;
this.args = args;
@ -352,7 +354,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
return evaluator.key(definition.getKey(), method, evalContext);
}
return keyGenerator.extract(method, args);
return keyGenerator.extract(target, method, args);
}
protected Collection<Cache<?, ?>> getCaches() {

View File

@ -28,7 +28,7 @@ import org.springframework.cache.KeyGenerator;
*/
public class DefaultKeyGenerator implements KeyGenerator<Object> {
public Object extract(Method method, Object... params) {
public Object extract(Object target, Method method, Object... params) {
if (params.length == 1) {
return params[0];
}