SPR-7832
+ expose the invocation params through the cache root object
+ update javadocs
This commit is contained in:
Costin Leau
2011-03-28 11:36:05 +00:00
parent a20e73b148
commit eb4b68ffda
9 changed files with 125 additions and 10 deletions

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -40,4 +40,6 @@ public interface CacheableService<T> {
Number nullInvocations();
T rootVars(Object arg1);
}

View File

@@ -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();