Yuval Adam
Yuval Adam

Reputation: 165242

Does this type of caching scheme have a name?

Consider the basic caching method: you lookup a key in the cache, if it's not there you go fetch it from main persistent storage. The value expires if the cache is full with other values or if the TTL passes.

Now, consider a slighty alternate version of a cache: you lookup a key, if it's not there you have to get it, nothing new here. But what if you lookup a key and the value has expired due to TTL, but instead you return that stale value, and asynchronously update the value so that next request will already see a fresh value (and TTL respectively reset)?

Does this caching scheme have a name? Does it have any cons we're missing out on?

Upvotes: 2

Views: 61

Answers (1)

James
James

Reputation: 8586

I don't know that it's named, but we've certainly used a scheme wherein data is cached for up to N minutes, but after N/2 minutes, a thread is spawned in the background to update the data.

It's good if: A) the computations are expensive, and B) you can't, absolutely, wait for a fresh computation.

Bad if: A) you need completely up to date information at any point. B) computations are very infrequent. In this case, your data may be, say, hours out of date.

Upvotes: 1

Related Questions