Created
September 24, 2013 22:17
-
-
Save glaforge/6692100 to your computer and use it in GitHub Desktop.
Safer usage of memcache service in Google App Engine
This file contains 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
// when doing the following... | |
if (ms.containsKey(key)) { | |
return ms.get(key); | |
} else { | |
// ... fetch and cache | |
} | |
// you run the risk that between the existence check in the if statement | |
// and the moment you actually call the get, | |
// memcache might have actually expired that key/value | |
// instead, in Gaelyk, we tend to do: | |
def result = ms.get(key) | |
if (ms == null) { | |
// ... fetch and cache | |
} | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment