SPR-8007
SPR-7832 + expose the invocation params through the cache root object + update javadocs
This commit is contained in:
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.AopProxyUtils;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -137,6 +138,16 @@ public abstract class AbstractAnnotationTest {
|
||||
assertTrue(cache.containsKey(keyName));
|
||||
}
|
||||
|
||||
public void testRootVars(CacheableService service) {
|
||||
Object key = new Object();
|
||||
Object r1 = service.rootVars(key);
|
||||
assertSame(r1, service.rootVars(key));
|
||||
Cache<Object, Object> cache = cm.getCache("default");
|
||||
// assert the method name is used
|
||||
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
|
||||
assertTrue(cache.containsKey(expectedKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheable() throws Exception {
|
||||
testCacheable(cs);
|
||||
@@ -205,4 +216,14 @@ public abstract class AbstractAnnotationTest {
|
||||
public void testClassMethodName() throws Exception {
|
||||
testMethodName(ccs, "namedefault");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootVars() throws Exception {
|
||||
testRootVars(cs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassRootVars() throws Exception {
|
||||
testRootVars(ccs);
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,11 @@ public class AnnotatedClassCacheableService implements CacheableService {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Cacheable(value = "default", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
public Object rootVars(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
public Object nullValue(Object arg1) {
|
||||
nullInvocations.incrementAndGet();
|
||||
return null;
|
||||
|
||||
@@ -40,4 +40,6 @@ public interface CacheableService<T> {
|
||||
|
||||
Number nullInvocations();
|
||||
|
||||
T rootVars(Object arg1);
|
||||
|
||||
}
|
||||
@@ -59,6 +59,11 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Cacheable(value = "default", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
public Long rootVars(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Cacheable("default")
|
||||
public Long nullValue(Object arg1) {
|
||||
nullInvocations.incrementAndGet();
|
||||
|
||||
Reference in New Issue
Block a user