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

Add defaut non-distributed cache lock implementation. #19

Open
singulared opened this issue Jun 1, 2021 · 0 comments
Open

Add defaut non-distributed cache lock implementation. #19

singulared opened this issue Jun 1, 2021 · 0 comments
Labels
cache locks Cache locks related issues enhancement New feature or request
Milestone

Comments

@singulared
Copy link
Member

singulared commented Jun 1, 2021

Cache locks are the main protection from the dogpile effect.
As main functionality (not related to some backend implementation) I suppose next simple structure.

Use something like a HasMap<&str, AsyncRwLock<CachedValue>>
where the key is a cache key of the current request and AsyncRWLock is an async version of classic RwLock (or some light pub-sub mechanic like tokio watch or one-shot channels).

How it should work:

  1. First request with cache key A to Upstream will create a record in a Hash table. and send a request to Upstream
  2. Second and next requests to Upstream with cache key A will check records on the hash table and subscribe to value changes (or asynchronous wait for changes)
  3. After first request will be resolved in Upstream cache should publish result to all consumers/waiters and remove record from HashMap

We should extend Backend trait with cache lock related methods with a default implementation.
I think this implementation should integrate with the stale cache mechanic in case of returns stale data while the lock not released (if the stale cache is enabled).

@singulared singulared added the enhancement New feature or request label Jun 1, 2021
@singulared singulared added this to the 0.3.0 milestone Jun 1, 2021
@singulared singulared removed this from the 0.3.0 milestone Jul 5, 2023
@singulared singulared added locks cache locks Cache locks related issues and removed locks labels Jul 5, 2023
@singulared singulared added this to the hitboxd-alpha milestone Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cache locks Cache locks related issues enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant