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 @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down