-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timeToLive() returns floats #35
Comments
Does this break anything other than expectations? Milliseconds can be fractional too. |
It causes a problem in https://github.com/lukechilds/cacheable-request. Since this is the root cause of the problem, I opened the issue here. That's the error I'm getting in cacheable-request which is coming from Keyv I think: code snippet in cacheable-request: let ttl = opts.strictTtl ? response.cachePolicy.timeToLive() : undefined;
if (opts.maxTtl) {
ttl = ttl ? Math.min(ttl, opts.maxTtl) : opts.maxTtl;
}
await this.cache.set(key, value, ttl); The program gets to In order to trigger this behavior I'm setting |
If you think this behavior is correct, it's fine, I'll just open an issue in cacheable-request. let me know. |
Not always of course, but in some cases
timeToLive()
returns floats.Which makes sense since in
maxAge()
there's a division by 1000 and then later a multiplication by 1000 done bytimeToLive()
, yet the code ignores computers' struggle with float arithmetic.Since the doc mentions
timeToLive()
returns time in milliseconds, one would expect it to return an integer.Math.round()
in the correct spot or some other solution would be appreciated, let me know what you think.The text was updated successfully, but these errors were encountered: