Introduce alias for 'value' attribute in caching annotations
This commit introduces new 'cacheNames' attributes (analogous to the existing attribute of the same name in @CacheConfig) as aliases for the 'value' attributes in @Cacheable, @CachePut, and @CacheEvict. In addition, SpringCacheAnnotationParser.getAnnotations() has been refactored to support synthesized annotations. Issue: SPR-11393
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -60,71 +60,71 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", allEntries = true)
|
||||
@CacheEvict(cacheNames = "testCache", allEntries = true)
|
||||
public void evictAll(Object arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", beforeInvocation = true)
|
||||
@CacheEvict(cacheNames = "testCache", beforeInvocation = true)
|
||||
public void evictEarly(Object arg1) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", key = "#p0")
|
||||
@CacheEvict(cacheNames = "testCache", key = "#p0")
|
||||
public void evict(Object arg1, Object arg2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", key = "#p0", beforeInvocation = true)
|
||||
@CacheEvict(cacheNames = "testCache", key = "#p0", beforeInvocation = true)
|
||||
public void invalidateEarly(Object arg1, Object arg2) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", key = "#p0")
|
||||
@Cacheable(cacheNames = "testCache", key = "#p0")
|
||||
public Object key(Object arg1, Object arg2) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache")
|
||||
@Cacheable("testCache")
|
||||
public Object varArgsKey(Object... args) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", key = "#root.methodName + #root.caches[0].name")
|
||||
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.caches[0].name")
|
||||
public Object name(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
public Object rootVars(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", keyGenerator = "customKyeGenerator")
|
||||
@Cacheable(cacheNames = "testCache", keyGenerator = "customKyeGenerator")
|
||||
public Object customKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", keyGenerator = "unknownBeanName")
|
||||
@Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName")
|
||||
public Object unknownCustomKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", cacheManager = "customCacheManager")
|
||||
@Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager")
|
||||
public Object customCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", cacheManager = "unknownBeanName")
|
||||
@Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName")
|
||||
public Object unknownCustomCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(value = "testCache", condition = "#arg.equals(3)")
|
||||
@CachePut(cacheNames = "testCache", condition = "#arg.equals(3)")
|
||||
public Object conditionalUpdate(Object arg) {
|
||||
return arg;
|
||||
}
|
||||
@@ -171,19 +171,19 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(value = "secondary", key = "#p0") })
|
||||
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#p0") })
|
||||
public Object multiEvict(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(cacheable = { @Cacheable(value = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
|
||||
@Caching(cacheable = { @Cacheable(cacheNames = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
|
||||
public Object multiCacheAndEvict(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(cacheable = { @Cacheable(value = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") })
|
||||
@Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") })
|
||||
public Object multiConditionalCacheAndEvict(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(value="primary", key="#result.id")
|
||||
@CachePut(cacheNames = "primary", key = "#result.id")
|
||||
public TestEntity putRefersToResult(TestEntity arg1) {
|
||||
arg1.setId(Long.MIN_VALUE);
|
||||
return arg1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -52,83 +52,83 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", allEntries = true)
|
||||
@CacheEvict(cacheNames = "testCache", allEntries = true)
|
||||
public void evictAll(Object arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", beforeInvocation = true)
|
||||
@CacheEvict(cacheNames = "testCache", beforeInvocation = true)
|
||||
public void evictEarly(Object arg1) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", key = "#p0")
|
||||
@CacheEvict(cacheNames = "testCache", key = "#p0")
|
||||
public void evict(Object arg1, Object arg2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "testCache", key = "#p0", beforeInvocation = true)
|
||||
@CacheEvict(cacheNames = "testCache", key = "#p0", beforeInvocation = true)
|
||||
public void invalidateEarly(Object arg1, Object arg2) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", condition = "#classField == 3")
|
||||
@Cacheable(cacheNames = "testCache", condition = "#classField == 3")
|
||||
public Long conditional(int classField) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", unless = "#result > 10")
|
||||
@Cacheable(cacheNames = "testCache", unless = "#result > 10")
|
||||
public Long unless(int arg) {
|
||||
return (long) arg;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", key = "#p0")
|
||||
@Cacheable(cacheNames = "testCache", key = "#p0")
|
||||
public Long key(Object arg1, Object arg2) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache")
|
||||
@Cacheable("testCache")
|
||||
public Long varArgsKey(Object... args) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", key = "#root.methodName")
|
||||
@Cacheable(cacheNames = "testCache", key = "#root.methodName")
|
||||
public Long name(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
public Long rootVars(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", keyGenerator = "customKeyGenerator")
|
||||
@Cacheable(cacheNames = "testCache", keyGenerator = "customKeyGenerator")
|
||||
public Long customKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", keyGenerator = "unknownBeanName")
|
||||
@Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName")
|
||||
public Long unknownCustomKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", cacheManager = "customCacheManager")
|
||||
@Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager")
|
||||
public Long customCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "testCache", cacheManager = "unknownBeanName")
|
||||
@Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName")
|
||||
public Long unknownCustomCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(value = "testCache", condition = "#arg.equals(3)")
|
||||
@CachePut(cacheNames = "testCache", condition = "#arg.equals(3)")
|
||||
public Long conditionalUpdate(Object arg) {
|
||||
return Long.valueOf(arg.toString());
|
||||
}
|
||||
@@ -178,20 +178,20 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
}
|
||||
|
||||
@Override
|
||||
//FIXME @Caching(evict = { @CacheEvict("primary"), @CacheEvict(value = "secondary", key = "#p0"), @CacheEvict(value = "primary", key = "#p0 + 'A'") })
|
||||
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(value = "secondary", key = "#p0") })
|
||||
//FIXME @Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#p0"), @CacheEvict(cacheNames = "primary", key = "#p0 + 'A'") })
|
||||
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#p0") })
|
||||
public Long multiEvict(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(cacheable = { @Cacheable(value = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
|
||||
@Caching(cacheable = { @Cacheable(cacheNames = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
|
||||
public Long multiCacheAndEvict(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(cacheable = { @Cacheable(value = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") })
|
||||
@Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") })
|
||||
public Long multiConditionalCacheAndEvict(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(value="primary", key="#result.id")
|
||||
@CachePut(cacheNames = "primary", key = "#result.id")
|
||||
public TestEntity putRefersToResult(TestEntity arg1) {
|
||||
arg1.setId(Long.MIN_VALUE);
|
||||
return arg1;
|
||||
|
||||
Reference in New Issue
Block a user