3 ms·
About: > The common pattern for application level caching data = cache.get('stuff') if data is None: data = list(Stuff.objects.all()) cache.se
by byroot 13y ago
About:
> The common pattern for application level caching
data = cache.get('stuff')
if data is None:
data = list(Stuff.objects.all())
cache.set('stuff', data)
return data
I'm wondering if you simplified the example or if you are just not preventing cache regen race conditions ?
Some other frameworks just put back the expired data for a few seconds while the new one is being regenerated to avoid having multiple workers building the same thing.
e.g. rails: https://github.com/rails/rails/blob/3182295ce2fa01b02cb9af0b977a9cf83cc5d9aa/activesupport/lib/active_support/cache.rb#L539 https://github.com/rails/rails/blob/3182295ce2fa01b02cb9af0b...
- mattrobenolt 13y agoThis is a very simplified example. We do something similar to avoid a stampede.