Skip to content

Provide a @CacheConfig annotation to share class-level customizations [SPR-11316] #15940

Closed
@spring-projects-issues

Description

@spring-projects-issues

Stéphane Nicoll opened SPR-11316 and commented

#13338 and #15257 have introduced two customisations related to the cache operation: cache manager and key generator.

The feature is tedious and error-prone as these customisations have to be set for each and every operation. The idea here is to introduce a new annotation @CacheConfig that could be set at class-level only and that would gather those customisations as well as the default cache name. Something like:

@CacheConfig(cacheManager = "myCacheManager")
public class FooRepository {

  @Cacheable("test)
  public void getFoo(String id) { ... }

}

If a caching operation specifies its own cache manager, key generator or cache names, that one is used instead of the default.

In other words, this is about giving 3 levels of customisation:

  1. General level (the global "cacheManager", "keyGenerator"; not available for cache names)
  2. Class level (through the @CacheConfig annotation)
  3. Operation level (through the explicit caching operation such as @Cacheable)

Issue Links:

Referenced from: commits 2b89c1a, 3c28301

0 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions