-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature Request: Add .clearStats() to Cache Interface #215
Comments
The statistics are documented as "monotonically increasing over the lifetime of the cache" so this is not directly supported. You can emulate it using the volatile CacheStats snapshot = CacheStats.empty();
void clear() {
cache.invalidateAll();
snapshot = cache.stats();
}
CacheStats stats() {
return cache.stats().minus(snapshot);
} Alternatively, you can provide your own Generally this isn't a problem if you export your statistics into a time series database, e.g. using Dropwizard Metrics. Then one can run computations, like a time window, over the data set. These systems tend to expect increasing values rather than each actor performing its own computations, like histograms, by delegating that work to the metrics application. |
The rational when designing this for Guava (Kevin's comment):
|
Hi Ben, thanks for the alternative implementation suggestion! (This resetting, user-initiated, is so rare I'm considering also just recreating the cache when it occurs.) Closing this ticket. |
When calling cache.invalidateAll(), I would also like to erase the CacheStats object returned by Cache.stats() so the stats all start at zero again. I can't see any way to that with Caffeine currently. One way I can see is to add .clearStats() to the Cache object, another option would be to add a boolean to the Cache.invalidateAll() method, i.e., .invalidateAll(boolean clearStats).
The text was updated successfully, but these errors were encountered: