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
Logging hit / miss #427
Comments
I suppose you could supply a custom StatsCounter that logs on the hit/miss methods. You would probably want to collect stats anyway to monitor the hit rates. |
Unfortunately, a custom
an additional code has to be written (Cache Configuration, CacheManager bean, StatsCounter implementation...) Perhaps it could be possible to add hit/miss logging at debug or trace level directly to the cache implementation? I think it would be a very welcome addition for many users. |
Oh, you're right. It is too limited for this case. I am hesitant to add logging on the hot paths, as we currently only do so on failure conditions that are may be accidentally swallowed. It would require that we capture and track state just for logging, e.g. concurrency might cause us to print the wrong value if updated, so even when disabled there can be overhead to ensure correct propagation. For stats we don't need to do that since they only need the resulting behavior to increment counters by. The cache is really just a fancier We do provide a JCache adapter, which has those frameworky concepts. That could be argued to include this richer logging. However JCache is largely a failed standard due to its ugly, often broken, and non-idiomatic API. We offer that for simpler integrations if used by a framework (like Hibernate), but most big vendors offer custom integrations into those frameworks because the jsr is mostly for show rather than actual usage. So I don't think us changing it there and having you switch over would be very useful for you, and expose your app to more quirks. Given your needs, your best bet is to ask Spring Cache to enhance their generic logging. As you noted, they already include some at trace level under |
Thank you, Ben, for detailed explanation. I understand your point. |
I'm using Caffeine via Spring
@Cacheable(sync=true)
annotation and setting parameters in application.yml (spring.cache.caffeine.*
).I'd like to see in log if the returned value has been retrieved from cache or not. How to achieve that?
The logging settings
only produce the output "Computed cache key ..." like
The text was updated successfully, but these errors were encountered: