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/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" 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);