Skip to content
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

cached: Add sync_writes_by_key #226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

raimannma
Copy link
Contributor

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:

@raimannma
Copy link
Contributor Author

raimannma commented Sep 19, 2024

@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?

@omid
Copy link
Contributor

omid commented Sep 19, 2024

What's the use case of sync_writes then?
I mean, why not to always lock by keys?

@raimannma
Copy link
Contributor Author

What's the use case of sync_writes then?

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.

@omid
Copy link
Contributor

omid commented Sep 19, 2024

Thanks for clarification.
I'm not a maintainer, but just to give some feedbacks, I'll add my suggestions to the PR.

cached_proc_macro/src/cached.rs Outdated Show resolved Hide resolved
cached_proc_macro/src/cached.rs Outdated Show resolved Hide resolved
cached_proc_macro/src/cached.rs Outdated Show resolved Hide resolved
cached_proc_macro/src/cached.rs Outdated Show resolved Hide resolved
cached_proc_macro/src/cached.rs Outdated Show resolved Hide resolved
cached_proc_macro/src/cached.rs Outdated Show resolved Hide resolved
@raimannma
Copy link
Contributor Author

Applied all the refactorings 👍

@raimannma
Copy link
Contributor Author

have to rewrite tests .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants