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 should participate in transactions [SPR-9966] #14600

Closed
spring-projects-issues opened this issue Nov 7, 2012 · 3 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Etienne Studer opened SPR-9966 and commented

As discussed with Jürgen this morning at W-JAX, if a @Cacheable method is called from within a @Transactional method and the transaction fails, the item is not removed from the cache for non-XA cache managers.

Basically, the item should not be added to the cache until the transaction has succeeded.

Alternatively, the item could be added immediately but removed if the transaction fails -> this would allow to get the cached item during the transaction, which helps if the item needs is accessed multiple times.


Affects: 3.1.1

Referenced from: commits e2f418a

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I'm using a slightly different approach now: decorating the target CacheManager with a TransactionAwareCacheManager which performs afterCommit synchronization for all put operations that happen within a Spring-managed transaction. The rationale is that it's not just about @Cacheable, it's about any put operations that happen within a transaction. And CacheManager decoration seems to be a fine way of controlling that behavior.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Etienne Studer commented

Nice, sounds great!

Etienne

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This is available both as a TransactionAwareCacheManagerProxy for any target CacheManager and as a built-in "transactionAware" flag on EhCache/JCacheCacheManager. It synchronizes all put as well as evict operations with the after-commit phase of an ongoing transaction, if any.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.2 RC2 milestone Jan 11, 2019
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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants