Skip to content

Support CacheErrorHandler in TransactionAwareCacheDecorator - #37289

Open
harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:gh-28554
Open

harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:gh-28554

Conversation

@harrisleesh

Copy link
Copy Markdown
Contributor

A CacheErrorHandler configured via CachingConfigurer only applies within intercepted cache invocations. With transaction-aware caching, put/evict/clear are deferred to the after-commit phase and run outside the intercepted invocation, so failures of the deferred operations bypass the configured error handler and propagate to the caller of the transaction commit — as reported in gh-28554, this prevents suppressing cache backend outages (e.g. Redis timeouts) via LoggingCacheErrorHandler.

This PR follows the direction of the reporter's earlier attempt and completes the wiring question left open there:

  • TransactionAwareCacheDecorator gains an optional CacheErrorHandler constructor argument, invoked for put/evict/clear failures in the after-commit phase. Without a handler, failures propagate exactly as before — no behavior change for existing usage.
  • AbstractTransactionSupportingCacheManager exposes a matching errorHandler property, applied in decorateCache(..), so cache manager implementations that extend it (e.g. RedisCacheManager) and integration layers (e.g. Boot's auto-configuration) can propagate the interception-level handler to the decorator.

Tests cover handler invocation for all three deferred operations and pin the existing propagation behavior when no handler is configured.

Closes gh-28554

A CacheErrorHandler configured via CachingConfigurer only applies
within intercepted cache invocations. With transaction-aware caching,
put, evict and clear operations are deferred to the after-commit
phase and run outside the intercepted invocation, so failures of the
deferred operations bypass the configured error handler and propagate
to the caller of the transaction commit. In particular, this prevents
suppressing cache backend outages via LoggingCacheErrorHandler.

TransactionAwareCacheDecorator now optionally accepts a
CacheErrorHandler to invoke for put, evict and clear failures in the
after-commit phase. AbstractTransactionSupportingCacheManager exposes
a corresponding errorHandler property, applied when decorating caches
for transaction awareness. Without an error handler, failures are
propagated as before.

Closes spring-projectsgh-28554

Signed-off-by: seonghun lee <harrisleesh@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TransactionAwareCacheDecorator renders CacheErrorHandler useless

2 participants