diff --git a/index.js b/index.js index aa7c33e..5d7dcbf 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/test/caching-test.js b/test/caching-test.js index a54e8d8..0e9bc88 100644 --- a/test/caching-test.js +++ b/test/caching-test.js @@ -60,6 +60,15 @@ describe('caching tests', function() { expect(mockRedis['/']).to.be.undefined; }); }); + + it('does not cache 3xx error responses', function() { + let body = 'Redirect to '; + let mockResponse = { statusCode: 301 }; + + return cache.put('/', body, mockResponse).then(() => { + expect(mockRedis['/']).to.be.undefined; + }); + }); }); describe('custom keys tests', function() {