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
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function Cache () {
var _missCount = 0;
var _size = 0;
var _debug = false;
var MAX_TIMEOUT = 2147483647;

this.put = function(key, value, time, timeoutCallback) {
if (_debug) {
Expand All @@ -16,6 +17,8 @@ function Cache () {
throw new Error('Cache timeout must be a positive number');
} else if (typeof timeoutCallback !== 'undefined' && typeof timeoutCallback !== 'function') {
throw new Error('Cache timeout callback must be a function');
} else if (time > MAX_TIMEOUT) {
throw new Error('Cache timeout out of range');
}

var oldRecord = _cache[key];
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ describe('node-cache', function() {
}).to.throw();
});

it('should throw an error given a timeout that is too large', function() {
expect(function() {
cache.put('key', 'value', 2147483648);
}).to.throw();
});

it('should throw an error given a non-function timeout callback', function() {
expect(function() {
cache.put('key', 'value', 100, 'foo');
Expand Down