Skip to content

Instantly share code, notes, and snippets.

@dcramer
Created April 24, 2012 01:02
Show Gist options
  • Save dcramer/2475204 to your computer and use it in GitHub Desktop.
Save dcramer/2475204 to your computer and use it in GitHub Desktop.
with cache.Lock('key name'[, timeout]):
# do something that usually has a race thats too hard to solve
# best example
def get_or_create(model, **kwargs):
with cache.Lock('get_or_create:%s:%s' % (model, make_key(kwargs)):
model.objects.get_or_create(**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment