From f3005a6e5e49507a614668b301c4d057bdd521a8 Mon Sep 17 00:00:00 2001 From: Michael Cacciatore Date: Mon, 19 Jun 2017 10:31:23 -0400 Subject: [PATCH 1/2] Throw error is expire time is set too high --- index.js | 4 ++-- test.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index df1a8a5..690798e 100644 --- a/index.js +++ b/index.js @@ -12,8 +12,8 @@ function Cache () { console.log('caching: %s = %j (@%s)', key, value, time); } - if (typeof time !== 'undefined' && (typeof time !== 'number' || isNaN(time) || time <= 0)) { - throw new Error('Cache timeout must be a positive number'); + if (typeof time !== 'undefined' && (typeof time !== 'number' || isNaN(time) || time <= 0 || time >= Math.pow(2, 32) / 2)) { + throw new Error('Cache timeout must be a positive number that is less than 2^32'); } else if (typeof timeoutCallback !== 'undefined' && typeof timeoutCallback !== 'function') { throw new Error('Cache timeout callback must be a function'); } diff --git a/test.js b/test.js index a203274..b2865e3 100644 --- a/test.js +++ b/test.js @@ -64,6 +64,12 @@ describe('node-cache', function() { }).to.throw(); }); + it('should throw an error given a timeout of more than 2147483647', function() { + expect(function() { + cache.put('key', 'value', 2147483648); + }).to.throw(); + }); + it('should throw an error given a negative timeout', function() { expect(function() { cache.put('key', 'value', -100); From 92848049242796f3840c84ff6d44ccb0eb074a21 Mon Sep 17 00:00:00 2001 From: Michael Cacciatore Date: Mon, 19 Jun 2017 16:13:44 -0400 Subject: [PATCH 2/2] Update package.json to v0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 92ddf3c..026be60 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "storage" ], "main": "./index.js", - "version": "0.1.6", + "version": "0.2.0", "repository": { "type": "git", "url": "git://github.com/ptarjan/node-cache.git"