Skip to content

Commit 6091453

Browse files
committed
Introduce value alias for cacheNames in @⁠CacheConfig
Prior to this commit @⁠CacheConfig did not have a `value` attribute alias for `cacheNames`, even though the rest of the cache-related annotations (such as @⁠Cacheable, @⁠CachePut, etc.) do have a `value` / `cacheNames` alias pair. To address that inconsistency, this commit introduces a `value` alias for `cacheNames` in @⁠CacheConfig as well. See gh-35096 Closes gh-35152
1 parent c6a8df4 commit 6091453

File tree

8 files changed

+20
-9
lines changed

8 files changed

+20
-9
lines changed

spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineReactiveCachingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void fluxCacheDoesntDependOnFirstRequest(Class<?> configClass) {
129129
}
130130

131131

132-
@CacheConfig(cacheNames = "first")
132+
@CacheConfig("first")
133133
static class ReactiveCacheableService {
134134

135135
private final AtomicLong counter = new AtomicLong();

spring-context/src/main/java/org/springframework/cache/annotation/CacheConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.springframework.core.annotation.AliasFor;
26+
2527
/**
2628
* {@code @CacheConfig} provides a mechanism for sharing common cache-related
2729
* settings at the class level.
@@ -39,6 +41,13 @@
3941
@Documented
4042
public @interface CacheConfig {
4143

44+
/**
45+
* Alias for {@link #cacheNames}.
46+
* @since 7.0
47+
*/
48+
@AliasFor("cacheNames")
49+
String[] value() default {};
50+
4251
/**
4352
* Names of the default caches to consider for caching operations defined
4453
* in the annotated class.
@@ -47,7 +56,9 @@
4756
* configured {@link #cacheResolver()} which typically delegates to
4857
* {@link org.springframework.cache.CacheManager#getCache}.
4958
* For further details see {@link Cacheable#cacheNames()}.
59+
* @see #value
5060
*/
61+
@AliasFor("value")
5162
String[] cacheNames() default {};
5263

5364
/**

spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public void multipleCacheConfig() {
443443
}
444444

445445

446-
@CacheConfig(cacheNames = "myCache")
446+
@CacheConfig("myCache")
447447
private interface CacheConfigIfc {
448448

449449
@Cacheable

spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void cacheErrorHandlerWithLoggingCacheErrorHandlerAndOperationExceptionAndSync()
256256
}
257257

258258

259-
@CacheConfig(cacheNames = "first")
259+
@CacheConfig("first")
260260
static class ReactiveCacheableService {
261261

262262
private final AtomicLong counter = new AtomicLong();
@@ -282,7 +282,7 @@ Flux<Long> cacheFlux(Object arg) {
282282
}
283283

284284

285-
@CacheConfig(cacheNames = "first")
285+
@CacheConfig("first")
286286
static class ReactiveSyncCacheableService {
287287

288288
private final AtomicLong counter = new AtomicLong();
@@ -304,7 +304,7 @@ Flux<Long> cacheFlux(Object arg) {
304304
}
305305

306306

307-
@CacheConfig(cacheNames = "first")
307+
@CacheConfig("first")
308308
static class ReactiveFailureCacheableService {
309309

310310
private final AtomicBoolean cacheFutureInvoked = new AtomicBoolean();

spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ interface FooService {
200200
}
201201

202202

203-
@CacheConfig(cacheNames = "testCache")
203+
@CacheConfig("testCache")
204204
static class FooServiceImpl implements FooService {
205205

206206
private final AtomicLong counter = new AtomicLong();

spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public Cache mockCache() {
261261

262262
}
263263

264-
@CacheConfig(cacheNames = "test")
264+
@CacheConfig("test")
265265
public static class SimpleService {
266266
private AtomicLong counter = new AtomicLong();
267267

spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public SimpleService simpleService() {
121121

122122
}
123123

124-
@CacheConfig(cacheNames = "test")
124+
@CacheConfig("test")
125125
public static class SimpleService {
126126
private AtomicLong counter = new AtomicLong();
127127

spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public SimpleService simpleService() {
206206
}
207207

208208

209-
@CacheConfig(cacheNames = "default")
209+
@CacheConfig("default")
210210
static class SimpleService {
211211

212212
private final AtomicLong counter = new AtomicLong();

0 commit comments

Comments
 (0)