Skip to content

Instantly share code, notes, and snippets.

@ionelmc
Created October 25, 2013 11:50
Show Gist options
  • Select an option

  • Save ionelmc/7153461 to your computer and use it in GitHub Desktop.

Select an option

Save ionelmc/7153461 to your computer and use it in GitHub Desktop.
val = cache.get(key)
if val:
return val
else:
with cache.lock(key):
val = cache.get(key)
if val:
return val
else:
# DO EXPENSIVE WORK
val = ...
cache.set(key, value)
return val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment