feat!: change TTL unit from seconds to milliseconds#30
Merged
flyingsquirrel0419 merged 7 commits intomainfrom May 1, 2026
Merged
feat!: change TTL unit from seconds to milliseconds#30flyingsquirrel0419 merged 7 commits intomainfrom
flyingsquirrel0419 merged 7 commits intomainfrom
Conversation
BREAKING CHANGE: All TTL values (ttl, negativeTtl, staleWhileRevalidate, staleIfError, ttlJitter, refreshAhead, adaptiveTtl step/maxTtl) now expect milliseconds instead of seconds, aligning with Node.js conventions. - StoredValue envelope: freshTtlSeconds -> freshTtlMs (wire format change) - TtlResolver: internal TTL now in milliseconds - MemoryLayer/DiskLayer: removed * 1000 conversion (TTL now ms directly) - RedisLayer: added / 1000 conversion for Redis EX command - All tests and documentation updated Refs #25
niksy
reviewed
May 1, 2026
| const normalizedKey = this.withPrefix(entry.key) | ||
| if (entry.ttl && entry.ttl > 0) { | ||
| pipeline.set(normalizedKey, payload as never, 'EX', entry.ttl) | ||
| pipeline.set(normalizedKey, payload as never, 'EX', Math.ceil(entry.ttl / 1_000)) |
There was a problem hiding this comment.
Why not use PX? It’s the milliseconds equivalent to EX
Replace 'EX' + Math.ceil(ttl / 1000) with 'PX' + ttl for millisecond precision. The rewrite path converts Redis TTL seconds to ms. Suggested-by: @niksy
niksy
reviewed
May 1, 2026
| @@ -366,7 +366,7 @@ export class RedisLayer implements CacheLayer { | |||
There was a problem hiding this comment.
Does it make sense to use PTTL here to keep it consistent with milliseconds?
a3d0948 to
86c26c4
Compare
|
Wanted to point out that this should have bumped package version to major (2.0.0) instead of minor (1.4.0) since it is a breaking change. Although there aren’t that many users of the package right now, you should probably take more care in the future when releasing breaking changes. |
Owner
Author
|
Oh my mistake . I will update my package to 2.0.0 right now! Thanks 🙏 |
Owner
Author
|
Updated ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Convert all TTL values from seconds to milliseconds, aligning with Node.js conventions (
setTimeout,Date.now(), etc.).Breaking Changes
All public TTL options now expect milliseconds instead of seconds:
Affected options:
ttl,negativeTtl,staleWhileRevalidate,staleIfError,ttlJitter,refreshAhead,adaptiveTtl.step,adaptiveTtl.maxTtl, and allLayerTtlMapvalues.Changes
StoredValuefreshTtlSeconds→freshTtlMs(wire format), removed* 1_000conversionTtlResolverDEFAULT_NEGATIVE_TTL_MS = 60_000MemoryLayer* 1_000— uses ms directly forDate.now() + ttlDiskLayerRedisLayerMath.ceil(ttl / 1_000)for RedisEXcommandMemcachedLayerRefs #25