Within Cache abstraction, log when a value was found for a key, and when not. [SPR-11654] #16277
We rely heavily on the Spring Cache et al family of abstractions. While the JMX statistics available for some caches are useful, in day to day development and production debugging it's often been essential to know of a particular object was provided by an implementation of Cache or if a backing store (ie: the
In short, can we please have some cursory logging at debug level when a value is fetched from a Cache (as in, the key produced a value) and when no value was available? Ideally, the key would be logged in both cases. Optionally, a 3rd log message can be given for the value (with key) at trace level.
I leave it to you to decide where this will go, so long as this is the default behavior.
1 votes, 2 watchers
Stéphane Nicoll commented
We already log the key (that can be improved) but regarding the cache hit/miss this may become a duplicate log with the caching providers log itself. With regard to cache miss, you can get that information by a log of your own in the annotated method.
We may consider adding a log for a cache hit. Any idea for the format? Thanks!
Brandon Zeeb commented
In my investigation, there is not an overlap with other providers. I scoured the EhCache source as well as running the root logger at TRACE and did not see any indication of cache hit/miss in the logs. In addition, by using a Spring Cache abstraction, we all hope to remove ourselves from implementation specific Cache provider details, so even if EhCache did have a logger, I would not care.
I do not have a requirement for the specific log format, but within the message it would prefer to see:
An example might be:
I put it to you to devise a log statement format that is consistent with your logging standards and any other existing patterns.
As a second statement, it would be valuable to log the retrieved Value as a String at TRACE level. It would also be preferable to only log the first N bytes or characters of this value. This is an optional requirement, but should also contain the key and cache name.