Skip to content

Instantly share code, notes, and snippets.

@jardakotesovec
Last active August 29, 2015 14:13
Show Gist options
  • Save jardakotesovec/bdd20f8b3a622441c212 to your computer and use it in GitHub Desktop.
Save jardakotesovec/bdd20f8b3a622441c212 to your computer and use it in GitHub Desktop.
exports.register = function (server, options, next) {
server.dependency('vision');
var cache = server.cache({
expiresIn: 30 * 1000,
generateFunc: function (id, next) {
server.render(id.template, id.context, id.options, function(err, rendered){
next(null rendered);
})
}
});
server.decorate('reply', 'viewCache', function (template, context, options) {
var id = JSON.stringify({template: template, context:context, options: options}); // I would recommend to shorten key somehow using some good checksum
return this.response(cache.get({id:id, template: template, context: context, options:options}));
});
return next();
};
exports.register.attributes = {
pkg: require('../package.json')
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment