Skip to content

Publish ApplicationEvents for cache operations#36996

Open
senocak wants to merge 6 commits into
spring-projects:mainfrom
senocak:feature/senocak/cache-operation-events
Open

Publish ApplicationEvents for cache operations#36996
senocak wants to merge 6 commits into
spring-projects:mainfrom
senocak:feature/senocak/cache-operation-events

Conversation

@senocak

@senocak senocak commented Jul 2, 2026

Copy link
Copy Markdown

This PR introduces ApplicationEvent publishing for cache write operations (put, evict, clear) in Spring's caching infrastructure. Currently, Spring's cache abstraction provides no mechanism to observe or react to cache mutations triggered by @Cacheable, @CachePut, and @CacheEvict annotations.

Spring's cache infrastructure intercepts annotated methods and performs cache operations, but:

  • No events are published when an entry is inserted, updated, or evicted
  • No method-level context is available to cache decorators or wrappers
  • No hooks exist for reactive or asynchronous side effects after cache mutations

Modified Classes

  • CacheAspectSupport: Holds an optional ApplicationEventPublisher, publishes events after successful doPut(), doEvict(), and doClear() calls in performCachePut() and performCacheEvicts().
  • CacheInterceptor: Implements ApplicationEventPublisherAware to receive the publisher from the ApplicationContext.

All existing cache interceptor tests continue to pass. If no ApplicationEventPublisher is available (e.g., AspectJ mode), events are silently skipped. Existing Cache, CacheManager, and configuration interfaces are unchanged.

@senocak senocak force-pushed the feature/senocak/cache-operation-events branch from 19522bc to 013908d Compare July 2, 2026 11:26
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 2, 2026
senocak added 2 commits July 2, 2026 14:49
Signed-off-by: TURKCELL\TCASENOCAK <anil.senocak@turkcell.com.tr>
Signed-off-by: TURKCELL\TCASENOCAK <anil.senocak@turkcell.com.tr>
@senocak senocak force-pushed the feature/senocak/cache-operation-events branch from 29fea82 to e7c36d0 Compare July 2, 2026 11:49
senocak added 4 commits July 2, 2026 14:59
Signed-off-by: TURKCELL\TCASENOCAK <anil.senocak@turkcell.com.tr>
Signed-off-by: TURKCELL\TCASENOCAK <anil.senocak@turkcell.com.tr>
Signed-off-by: TURKCELL\TCASENOCAK <anil.senocak@turkcell.com.tr>
Signed-off-by: TURKCELL\TCASENOCAK <anil.senocak@turkcell.com.tr>
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.

2 participants