Skip to content

Instantly share code, notes, and snippets.

@davej
Forked from EGreg/DRY
Created January 26, 2012 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davej/1680255 to your computer and use it in GitHub Desktop.
Save davej/1680255 to your computer and use it in GitHub Desktop.
Asynchronous cache failover example
function cacheOrDB (id, callback) {
asynchronousCache.get("id:"+id, function(err, myThing) {
if (myThing == null) {
asynchronousDB.query("SELECT * from something WHERE id = "+id, function(err, myThing) {
callback(err, myThing);
});
} else {
callback(err, myThing);
}
});
}
cacheOrDB("3244", function(err, myThing){
// Do something with myThing
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment