Created
April 24, 2012 01:02
-
-
Save dcramer/2475204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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