Skip to content

Instantly share code, notes, and snippets.

@glaforge
Created September 24, 2013 22:17
Show Gist options
  • Save glaforge/6692100 to your computer and use it in GitHub Desktop.
Save glaforge/6692100 to your computer and use it in GitHub Desktop.
Safer usage of memcache service in Google App Engine
// 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