-
Notifications
You must be signed in to change notification settings - Fork 106
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 size 0 / Disable Cache #165
Comments
+1 to this. @jeromefroe Can you please consider reverting #150 which uses There are certain cases which capacity zero is pretty useful and ergonomic in the code as in for example to disable the cache mentioned above. It is a similar thing to pass an empty vector or buffer around.
|
If you wish to support a cache with zero capacity, you will need to return an Comparing it to a hash-map type may not be suitable because hash-maps typically have dynamic capacity and don't fail on insertions due to capacity limitations, as it increases on demand. Still, it should be possible to create a wrapper around the cache to handle the zero-capacity case and expose the desired APIs. |
NonZeroUsize for capacity is very nonergonomic and prevents some use-cases. For example a usize allows to disable caching by using capacity zero. see: jeromefroe#165 This reverts commit 0e415ef.
Not necessarily. enum ValueWrapper<'a, V> {
Borrowed(&'a V),
Owned(V),
} So that impl<'a, V> Borrow<V> for ValueWrapper<'a, V> {
fn borrow(&self) -> &V {
match self {
Self::Borrowed(v) => v,
Self::Owned(v) => v,
}
}
} so that effectively it is equivalent to I have implemented this idea in #177 |
v0.7x
had better ergonomics if you want to optionally disable the cache. That's not possible anymore withNonZeroUsize
, now you would need extra code for that use case.The text was updated successfully, but these errors were encountered: