Skip to content

Commit

Permalink
Clean route.cache. Closes #1249, Closes #1248
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Dec 21, 2013
1 parent 4d6bf6b commit b7252a4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
5 changes: 1 addition & 4 deletions lib/response/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ exports.cache = function (response, request, passThrough) {
ttl = request._route.cache.ttl();
}
}
else {
ttl = 0;
}

// Set header

if (ttl) {
var privacy = request.route.cache.privacy;
var privacy = (request.route.cache && request.route.cache.privacy) || 'default';
response.header('cache-control', 'max-age=' + Math.floor(ttl / 1000) + ', must-revalidate' + (privacy !== 'default' ? ', ' + privacy : ''));
}
else if (!passThrough) {
Expand Down
7 changes: 1 addition & 6 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ exports = module.exports = internals.Route = function (options, server, env) {

if (this.settings.cache) {
Utils.assert(this.method === 'get', 'Only GET routes can use a cache:', options.path);

this.settings.cache.privacy = this.settings.cache.privacy || 'default';
this.cache = new Catbox.Policy(this.settings.cache.expiresIn || this.settings.cache.expiresAt ? { expiresIn: this.settings.cache.expiresIn, expiresAt: this.settings.cache.expiresAt, staleIn: this.settings.cache.staleIn, staleTimeout: this.settings.cache.staleTimeout } : {});
}
else {
this.cache = new Catbox.Policy();
this.cache = new Catbox.Policy({ expiresIn: this.settings.cache.expiresIn, expiresAt: this.settings.cache.expiresAt });
}

// Handler
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ internals.routeConfigSchema = {
}).allow(true, false),
cache: Joi.object({
privacy: Joi.string().valid('default', 'public', 'private'),
expiresIn: Joi.number().without('expiresAt'),
expiresIn: Joi.number().xor('expiresAt'),
expiresAt: Joi.string()
}),
cors: Joi.boolean(),
Expand Down
2 changes: 1 addition & 1 deletion test/integration/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('Proxy', function () {
{ method: 'GET', path: '/handler', handler: function (request, reply) { reply.proxy({ uri: 'http://localhost:' + backendPort + '/item' }); } },
{ method: 'GET', path: '/handlerTemplate', handler: function (request, reply) { reply.proxy({ uri: '{protocol}://localhost:' + backendPort + '/item' }); } },
{ method: 'GET', path: '/handlerOldSchool', handler: function (request, reply) { reply.proxy({ host: 'localhost', port: backendPort }); } },
{ method: 'GET', path: '/cachedItem', handler: { proxy: { host: 'localhost', port: backendPort, ttl: 'upstream' } }, config: { cache: {} } },
{ method: 'GET', path: '/cachedItem', handler: { proxy: { host: 'localhost', port: backendPort, ttl: 'upstream' } } },
{ method: 'GET', path: '/clientCachedItem', handler: { proxy: { uri: 'http://localhost:' + backendPort + '/cachedItem', ttl: 'upstream' } } }
]);

Expand Down

0 comments on commit b7252a4

Please sign in to comment.