cached: Add sync_writes_by_key
Sync Writes by Key
This PR implements the sync_writes_by_key attribute, which works like sync_writes, but uses an individual lock per key.
This way you can call a method concurrently with different cache keys without locking the method (globally).
Related Issues:
- https://github.com/jaemk/cached/issues/158
- https://github.com/jaemk/cached/issues/62
- https://github.com/jaemk/cached/issues/81
@jaemk Can you review this? I tried to keep the changes very minimal.
The only thing I am not sure about is whether we need to worry about cleaning up the hashmap. So if a cache is invalid, we could remove the key from the hashmap.
Also I haven't tested with Redis cache storages, could there be a problem with redis?
What's the use case of sync_writes then?
I mean, why not to always lock by keys?
What's the use case of
sync_writesthen?
Good point.
I guess there could still be a use case where you want to lock a method independently of the key.
Also, using by_key is a bit more expensive because it has to keep track of multiple cache instances in the hashmap.
Thanks for clarification. I'm not a maintainer, but just to give some feedbacks, I'll add my suggestions to the PR.
Applied all the refactorings :+1:
have to rewrite tests .....
@jaemk Have you had a chance to look at this PR?
Thanks @raimannma (and @omid for reviewing)! Released under 0.55.1 - I changed one thing though, reverting the #[once] macro's sync_writes to a boolean since there was only one variant and the key doesn't apply
Thanks @raimannma (and @omid for reviewing)! Released under
0.55.1- I changed one thing though, reverting the#[once]macro'ssync_writesto a boolean since there was only one variant and the key doesn't apply
Great, thanks 👍