Skip to content

Instantly share code, notes, and snippets.

@crtr0
Created January 11, 2013 23:07
Show Gist options
  • Select an option

  • Save crtr0/4514731 to your computer and use it in GitHub Desktop.

Select an option

Save crtr0/4514731 to your computer and use it in GitHub Desktop.
findBy = exports.findBy = function(view, params, callback) {
var event;
if (event = eventsCache[view+JSON.stringify(params)]) {
callback(null, event);
}
else {
db.view('event', view, params, function(err, body) {
if (err) {
console.log(err);
callback(err, null);
}
else {
if (body.rows.length == 0) {
var msg = 'No match for: ' + view + ', ' + params;
console.log(msg);
callback(msg, null);
}
else {
event = body.rows[0].value;
eventsCache[view+JSON.stringify(params)] = event;
callback(null, event);
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment