Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ class RedisCache {
let statusCodeStr = statusCode && (statusCode + '');

if (statusCodeStr && statusCodeStr.length &&
(statusCodeStr.charAt(0) === '4' || statusCodeStr.charAt(0) === '5')) {
(statusCodeStr.charAt(0) === '4' || statusCodeStr.charAt(0) === '5' || statusCodeStr.charAt(0) === '3')) {
res();
return;
}

this.client.multi()
.set(key, body)
.expire(path, this.expiration)
.expire(key, this.expiration)
.exec(err => {
if (err) {
rej(err);
Expand Down
9 changes: 9 additions & 0 deletions test/caching-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ describe('caching tests', function() {
expect(mockRedis['/']).to.be.undefined;
});
});

it('does not cache 3xx error responses', function() {
let body = '<body>Redirect to </body>';
let mockResponse = { statusCode: 301 };

return cache.put('/', body, mockResponse).then(() => {
expect(mockRedis['/']).to.be.undefined;
});
});
});

describe('custom keys tests', function() {
Expand Down