-
Notifications
You must be signed in to change notification settings - Fork 879
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
Add new method GetItemsAndFlush #179
Comments
Just opened a PR #180 |
I wonder if there isn't a more generic way to implement this. What you want is:
But the "Items()" and "Flush()" are pretty specific to your use case. It's probably not appropriate to include that in a generic library. Someone else might want "Items(), "delete these six specific keys", "increment this one value" in there. Or something. Something like the
Would be much better. Would be rather tricky to implement well though. Maintaining your own wrapper with its own mutex would probably be better, although with a small performance hit due to an extra mutex, but that's in the nanosecond range so probably not an issue unless you really use it in a tight loop. |
I truly liked the idea of the
But now I am thinking more about the problem, and still don't think it's so specific. People often want to take a snapshot and clean the cache. A minor change maybe is returning the map when the
I can implement both in fact, but I think returning the map is way more simple, although I doubt Patrick reads these issues nowadays haha |
In your example, if you call You can't really use a regular mutex for this; I've been thinking about a nice way to solve these kind of issues (not the first time I've ran into it), but haven't really gotten around to actually implementing something.
Yes, I agree that would be good. Unfortunately also incompatible.
Probably not, no. But I've been maintaining a fork at https://github.com/arp242/zcache and keep an eye on things here. So what I'm really talking about is the best way to solve your use-case in my fork 😅 |
We are facing a situation where we need to flush the entire cache while capturing a snapshot of its exact state before doing so.
Using the
Items
function followed byFlush
is not concurrent safe because a Set operation could occur between the two calls, resulting in the Flush call mistakenly deleting newly added items.A workaround would be to use a mutex that prevents writes while these two sequential calls are being made. However, it is much simpler and more efficient to use the library's existing mutex.
The text was updated successfully, but these errors were encountered: