mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Support @CacheConfig("myCache") declarations for simplified config
The @CacheConfig section of the reference manual provides an example
that declares @CacheConfig("books").
However, unlike the @Cacheable, @CachePut, and @CacheEvict
annotations, @CacheConfig currently does not have a `value` alias for
the `cacheNames` attribute. Thus, the example in the reference manual
does not compile, and @CacheConfig(cacheNames = "books") would be the
supported way to declare that.
The driving factor for this commit is therefore to provide a simplified
and consistent programming model for users that only need to define
default cache names at the type level (like in the existing example in
the reference manual).
To address that, this commit introduces a `value` alias for
`cacheNames` in @CacheConfig.
See gh-35096
Closes gh-35152
(cherry picked from commit 6091453feb)
This commit is contained in:
+13
@@ -22,6 +22,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* {@code @CacheConfig} provides a mechanism for sharing common cache-related
|
||||
* settings at the class level.
|
||||
@@ -39,6 +41,15 @@ import java.lang.annotation.Target;
|
||||
@Documented
|
||||
public @interface CacheConfig {
|
||||
|
||||
/**
|
||||
* Alias for {@link #cacheNames}.
|
||||
* <p>Intended to be used when no other attributes are needed, for example:
|
||||
* {@code @CacheConfig("books")}.
|
||||
* @since 6.2.9
|
||||
*/
|
||||
@AliasFor("cacheNames")
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Names of the default caches to consider for caching operations defined
|
||||
* in the annotated class.
|
||||
@@ -47,7 +58,9 @@ public @interface CacheConfig {
|
||||
* configured {@link #cacheResolver()} which typically delegates to
|
||||
* {@link org.springframework.cache.CacheManager#getCache}.
|
||||
* For further details see {@link Cacheable#cacheNames()}.
|
||||
* @see #value
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String[] cacheNames() default {};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user