ptarjan / node-cache

A simple in-memory cache for nodejs
BSD 2-Clause "Simplified" License
1.59k stars 214 forks source link

If the cache timeout is sufficiently big, it doesn't work. #84

Open saltukalakus opened 7 years ago

saltukalakus commented 7 years ago

Set the timeout value to 999999999999, request the key back after 10 seconds and cache doesn't return the value. Observable in latest NPM version => 0.1.6

cache.put(key, value, 999999999999);

saltukalakus commented 7 years ago

In my Node.js test environment Number.MAX_SAFE_INTEGER returns 9007199254740991. Sufficiently bigger than 999999999999.

michaelcacciatore commented 7 years ago

Upon further investigation, this is because this library uses setTimeout to control the cache expiration. This means that the maximum value that can be passed in is 2147483647 (maximum positive 32 bit signed integer)

Source: https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args

ptarjan commented 7 years ago

Correct, the library should probably throw if you pass a higher value than setTimeout can handle. Want to send a PR?