Skip to content

Provide some synchronization between @Cacheable and @CacheEvict annotated methods [SPR-9304] #13942

@spring-projects-issues

Description

@spring-projects-issues

Mario Philipps opened SPR-9304 and commented

In many cases, @Cacheable annotated methods will read a given resource (such as a database table), and @CacheEvict annotated methods will update this resource. Unfortunately, there is a race condition that can lead to outdated cache contents. Consider the following schedule, with thread A reading the resource, thread B updating it:

A: entering @Cacheable
A: reading resource in state 1
B: entering @CacheEvict
B: updating resource to state 2
B: leaving @CacheEvict, invalidating the cache
A: leaving @Cacheable, writing state 1 to the cache

Now the resource is in state 2, the cache in state 1, but marked valid.

It would be great if there was some (optional) synchronization between the two cache annotations, that prevents such a race condition, if possible even in multi-node configurations.


Affects: 3.1.1

Issue Links:

5 votes, 14 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions