Skip to content

Instantly share code, notes, and snippets.

@cadecairos
Last active August 29, 2015 14:22
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 cadecairos/1218c4ba12d34c1d9ea8 to your computer and use it in GitHub Desktop.
Save cadecairos/1218c4ba12d34c1d9ea8 to your computer and use it in GitHub Desktop.
var db = require('./dbInterface');
exports = function(server, options, done) {
server.method('getResource', function(resourceId, next) {
db.find({
id: resourceId
}, function(err, data) {
if(err) {
return next(err);
}
next(null, data);
});
}, {
// uses the default cache client on the server, unless name is specified.
cache: {
// expires in 60 seconds
expiresIn: 60000,
// try to refresh after 30 seconds
staleIn: 30000,
// if refresh takes longer than 10 seconds, return cached value to client, refresh cached value in the background
staleTimeout: 10000
}
});
done();
};
exports.attributes = {
name: 'add two numbers server method'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment