From c87e831528a293a2aec636a23344a95760a761a1 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 16 Dec 2016 10:48:30 +0700 Subject: [PATCH 1/3] Update index.js not cache 3xx statuses --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index aa7c33e..35bb7d8 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ 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; } From bf5c47046d3ee306b73bb56785cb298979d60f81 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 16 Dec 2016 10:51:17 +0700 Subject: [PATCH 2/3] Update caching-test.js test --- test/caching-test.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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() { From fd55835184ebaac7249e52cc4fb81bd478c1e310 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 9 Jan 2017 18:05:34 +0700 Subject: [PATCH 3/3] Update index.js true key for expire --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 35bb7d8..5d7dcbf 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,7 @@ class RedisCache { this.client.multi() .set(key, body) - .expire(path, this.expiration) + .expire(key, this.expiration) .exec(err => { if (err) { rej(err);