Add @OnCacheHit annotation to intercept the cache hit #33642
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: declined
A suggestion or change that we don't feel we should currently apply
There is a common requirement to perform some actions in case cache was hit, for instance to log the actual hit, as in the mentioned issue.
For logging purposes, for instance:
org.springframework.cache
, which is not very convenient, since the log is predefined and cannot be customized.Cache
/CacheManager
directly. For instance, something like that:That of course can be done, but if you think about it, this turmoil is required here because of one simple thing - we want to log the cache hit.
Proposal:
I think it would be a good idea to introduce an annotation, such as
@OnCacheHit(cacheName="something", unless="SPEL")
This would've clearly made the code above unnecessary, becuase we can just do:
The text was updated successfully, but these errors were encountered: