HybridCache stampede protection is for single machine only
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 894
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 23
Description
### Description
All of the articles I read about HybridCache mention the cache stampede protection. I checked the source code here and see that the way it works is by checking for any existing operations and then joining them. That works great for the current machine, but if HybridCache is running on multiple machines (a likely use case for a distributed cache consumer), each individual machine doesnt know about other machine's attempts to populate the cache. This means that if multiple requests come in at the same time on different machines and encounter a cache miss, they all will perform the expensive operation to fetch the data and populate the cache, effectively negating the cache stampede protection.
I understand that in order to solve this properly, there needs to be some kind of distributed lock/sync mechanism. That may be outside the scope of HybridCache, but the documentation is a bit misleading in this regard. Is there some way to better describe or document the stampede protection so consumers understand its limitations?
### Reproduction Steps
Deploy code using HybridCache on multiple servers
Concurrently try to access a cached item from more than one server
Both servers will have a cache miss and try to load the data from source
### Expected behavior
Best case: when backed with an IDistributedCache implementation, the stampede protection is also distributed.
Alternative: documentation is updated to clarify how this works
### Actual behavior
Same data will be loaded from source on multiple machines
### Regression?
n/a
### Known Workarounds
_No response_
### Configuration
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.