-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Request: Some way to determine if future::Cache::get_with()
returned cached or fresh value
#136
Comments
It occurs to me that the future given to |
Technically, this will be very easy to implement. The only problem is that we cannot change I am very open to adding such method(s) but I would like to keep the core
Perhaps, something like this? // We will keep current `get_with` as is.
let val = cache.get_with(key, async {...}).await;
// For accessing advanced features, use a new `entry` method, which mimics `HashMap`'s `entry` method.
let result = cache.entry(key).or_insert_with(async {...}).await;
// `result` is a struct providing some methods to access its `bool` and `V` fields.
if result.is_fresh() {
info!("Fresh value");
}
let val = result.into_value(); // This consumes `self` and returns `V`. If we can come up with a nice interface, I would also hide unpopular |
Ideally the caller doesn't need to know for business logic purposes and we shouldn't corrupt our apis if only for debug logging. The main reason would be for stats, which in Caffeine has a pluggable Caffeine has this same problem with the backing When it is not possible or a much worse solution than native support, I think stashing these ad hoc methods somewhere else (e.g. |
I want to know if
future::Cache:get_with()
returned a cached or a fresh value. This is important for logging purposes. I imagine there are workarounds I could do involving heap-allocating a mutable boolean, setting it in the future I pass to the function, and testing it when the function returns, but that's very awkward. It would be great if the cache could simply tell me whether it was fresh or cached.The text was updated successfully, but these errors were encountered: