AurumAS/DoubleCache

Decorator for avoiding cache stampede

Ulriksen opened this issue · 1 comments

Cache stampede can occur when items are not in cache, and many clients try to read the same un-cached data at the same time. With DoubleCache the main problem is that each client process will try to call the data retrieve method. See https://en.wikipedia.org/wiki/Cache_stampede

There's several strategies, one of them is a longer expire time on the main cache entry and a marker entry with the original ttl. If the marker is not in Redis, the marker will be set, and only the first client will be responsible for re-calculating the value.The rest of the clients will be served stale content from Redis. Another approach would be to use shorter time for the marker interface and have some sort of cache population service/background worker.

Fixed in #21