Skip to content

Commit 5c3ceb8

Browse files
author
Costin Leau
committed
SPR-7971
+ add target object to KeyGenerator
1 parent 71d70a6 commit 5c3ceb8

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

org.springframework.context/src/main/java/org/springframework/cache/KeyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
*/
2727
public interface KeyGenerator<K> {
2828

29-
K extract(Method method, Object... params);
29+
K extract(Object target, Method method, Object... params);
3030
}

org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ protected class CacheOperationContext {
306306

307307
private CacheDefinition definition;
308308
private final Collection<Cache<?, ?>> caches;
309+
private final Object target;
309310
private final Method method;
310311
private final Object[] args;
311312

@@ -318,6 +319,7 @@ public CacheOperationContext(CacheDefinition operationDefinition, Method method,
318319
Object target, Class<?> targetClass) {
319320
this.definition = operationDefinition;
320321
this.caches = CacheAspectSupport.this.getCaches(definition);
322+
this.target = target;
321323
this.method = method;
322324
this.args = args;
323325

@@ -352,7 +354,7 @@ protected Object generateKey() {
352354
return evaluator.key(definition.getKey(), method, evalContext);
353355
}
354356

355-
return keyGenerator.extract(method, args);
357+
return keyGenerator.extract(target, method, args);
356358
}
357359

358360
protected Collection<Cache<?, ?>> getCaches() {

org.springframework.context/src/main/java/org/springframework/cache/support/DefaultKeyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class DefaultKeyGenerator implements KeyGenerator<Object> {
3030

31-
public Object extract(Method method, Object... params) {
31+
public Object extract(Object target, Method method, Object... params) {
3232
if (params.length == 1) {
3333
return params[0];
3434
}

0 commit comments

Comments
 (0)