-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Cache abstraction does not log hit / miss for synchronized access #25248
Comments
Hi, is there any news on this issue? |
Thanks for the report and the suggestion. This is fixed in the upcoming |
reading your patch... this was only fixed for synchronized? why not unsynchronized? why is it not for everything? I'm trying to figure out if I'm getting cache hits (seems to be misses), nothing is being logged for calls to this this method... even though I'm definitely calling it, it does seem to have cache misses.
just using simple cache per the reference docs as I have not configured anything regarding the cache starter. spring.cache.cache-names=book-divisions
spring.cache.caffeine.spec=maximumSize=1000,expireAfterAccess=60s |
worth mentioning if the log isn't saying it that method has no arguments |
General logging of hit / miss has been added in #16277.
For synchronized cache contexts (
@Cacheable(sync=true)
), no logging happens yet.It's also not that straightforward, since in that case the mapping function will be passed directly to the Cache implementation (e.g. Caffeine) and Spring has no knowledge about if the mapper function has been called or if the returned value has been retrieved from the cache.
What we can do? I would propose to decorate the mapping function with an "invoked" flag (which will tell if the function has been invoked by the cache implementation) and with a logging for the "miss" case. The logging directly inside the function is necessary because we want to log misses before invocation of the underlying mapper function. The flag "invoked" is necessary to recognize the "hit" case (we can only definitely say that after the value has been returned from the cache implementation).
Here is the place in the code:
spring-framework/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
Lines 377 to 384 in 1279b3b
The line
return wrapCacheValue(method, cache.get(key, () -> unwrapReturnValue(invokeOperation(invoker))));
could be changed to something like that:What do you think? Perhaps any easier solution possible?
The text was updated successfully, but these errors were encountered: