Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Cacheable key generator is called after invoking the cached method in case of a miss #31789

Closed
sergiuprdn opened this issue Dec 8, 2023 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@sergiuprdn
Copy link
Contributor

Affects: 6.1.1


We use @Cacheable on a few methods that have parameters of collection type and have a custom KeyGenerator implementation. In this key generator implementation we take into account each element of the input collections when creating the cache key.

After upgrading from Spring Boot 3.1.5 to 3.2.0 we noticed that CacheAspectSupport has changed its behaviour such that, in case of a miss, cache key generation is called after the @Cacheable method is invoked which means that the cache key might have changed if the collection elements were changed.

Previous versions were calculating the cache key for put before invoking the @Cacheable method, thus making sure the method parameters were not changed by the invocation.

@sergiuprdn sergiuprdn changed the title @Cacheable key generation is called after invoking the cached method in case of a miss @Cacheable key generator is called after invoking the cached method in case of a miss Dec 8, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 8, 2023
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 8, 2023
@jhoeller jhoeller self-assigned this Dec 8, 2023
@jhoeller jhoeller added this to the 6.1.2 milestone Dec 8, 2023
@jhoeller
Copy link
Contributor

jhoeller commented Dec 8, 2023

This seems to be caused by #31626 - we need to figure out a way to address both requirements without a regression there.

@jhoeller
Copy link
Contributor

jhoeller commented Dec 8, 2023

Actually, the earlier change #22769 seems to be the root cause here, #31626 just a follow-up effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants