Skip to content

Commit

Permalink
Removed view and directory from cachable responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Jul 21, 2013
1 parent b17c8b6 commit 5f5bcab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ internals.Request.handler = function (request, next) {

var lookup = function () {

// Lookun in cache
// Lookup in cache

request._route.cache.getOrGenerate(request.url.path, generate, function (err, value, cached, report) { // request.url.path contains query

Expand Down
14 changes: 6 additions & 8 deletions lib/response/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
var Fs = require('fs');
var Path = require('path');
var Async = require('async');
var Cacheable = require('./cacheable');
var Generic = require('./generic');
var Redirection = require('./redirection');
var Text = require('./text');
var Boom = require('boom');
var File = require('./file');
var Utils = require('../utils');
Expand All @@ -15,14 +16,14 @@ var Utils = require('../utils');
var internals = {};


// File response (Generic -> Cacheable -> Directory)
// File response (Generic -> Directory)

exports = module.exports = internals.Directory = function (paths, options) {

Utils.assert(this.constructor === internals.Directory, 'Directory must be instantiated using new');
Utils.assert(options, 'Options must exist');

Cacheable.call(this);
Generic.call(this);
this.variety = 'directory';
this.varieties.directory = true;

Expand All @@ -37,7 +38,7 @@ exports = module.exports = internals.Directory = function (paths, options) {
this._hasTrailingSlash = this._resource && (this._resource[this._resource.length - 1] === '/');
};

Utils.inherits(internals.Directory, Cacheable);
Utils.inherits(internals.Directory, Generic);


internals.Directory.prototype._prepare = function (request, callback) {
Expand Down Expand Up @@ -167,10 +168,7 @@ internals.Directory.prototype._generateListing = function (path, request, callba

html += '</ul></body></html>';

self._payload = [html];
self._headers['Content-Type'] = 'text/html';

return Cacheable.prototype._prepare.call(self, request, callback);
return callback(new Text(html, 'text/html'));
});
};

Expand Down
16 changes: 7 additions & 9 deletions lib/response/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ var internals = {
/*
/-- Stream -----|--- File
|
Generic --|--- Buffer /-- Text ----|-- Redirection
Generic --|--- Buffer
|
|--- Directory /-- Text ----|-- Redirection
| |
\-- Cacheable --|--- Empty
|
|-- Directory
|
|--- Object --|-- Error
|
|--- Cached
|--- Cacheable --|--- Empty
| |
\-- View |--- Object --|-- Error
|
\-- View
\-- Cached
*/

// Prototype response types
Expand Down
10 changes: 5 additions & 5 deletions lib/response/view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Load modules

var Cacheable = require('./cacheable');
var Generic = require('./generic');
var Utils = require('../utils');


Expand All @@ -9,11 +9,11 @@ var Utils = require('../utils');
var internals = {};


// View response (Generic -> Cacheable -> View)
// View response (Generic -> View)

module.exports = internals.View = function (manager, template, context, options) {

Cacheable.call(this);
Generic.call(this);
this.variety = 'view';
this.varieties.view = true;

Expand All @@ -25,7 +25,7 @@ module.exports = internals.View = function (manager, template, context, options)
};
};

Utils.inherits(internals.View, Cacheable);
Utils.inherits(internals.View, Generic);


internals.View.prototype._prepare = function (request, callback) {
Expand All @@ -49,7 +49,7 @@ internals.View.prototype._prepare = function (request, callback) {
self._flags.encoding = config.encoding;
}

return Cacheable.prototype._prepare.call(self, request, callback);
return Generic.prototype._prepare.call(self, request, callback);
});
};

4 changes: 2 additions & 2 deletions test/integration/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ describe('Response', function () {
});
});

it('returns a cached reply on second request', function (done) {
it('returns a fresh reply on second request when caching enabled', function (done) {

server.inject('/views/cache', function (res) {

Expand All @@ -1516,7 +1516,7 @@ describe('Response', function () {
server.inject('/views/cache', function (res) {

expect(res.result).to.exist;
expect(res.result).to.equal('<div>\n <h1>1</h1>\n</div>\n');
expect(res.result).to.equal('<div>\n <h1>2</h1>\n</div>\n');
expect(res.statusCode).to.equal(200);
done();
});
Expand Down

0 comments on commit 5f5bcab

Please sign in to comment.