node-lru-cache icon indicating copy to clipboard operation
node-lru-cache copied to clipboard

Issue with faked performance.now and this.starts being zeros

Open domarmstrong opened this issue 1 year ago • 1 comments

I'm seeing another issue with using sinon timers. With a faked performance.now, the initial result will be 0 until you advance the timer.

But the default fill of the starts array is 0 https://github.com/isaacs/node-lru-cache/blob/main/src/index.ts#L1478. That means any value set in the cache before you manually advance a timer is seem as not having a TTL.

You could argue in a real world situation you won't get a performance.now of 0. I think ideally the starts array should be initialised with null/undefineds instead? It seems like a bug that a cache with a ttl set should see it as not having a ttl because perf.now returned 0.

domarmstrong avatar Jan 16 '25 13:01 domarmstrong

@isaacs looks like there's already a related issue for what we've been discussing in #345

edward-simpson-byhiras avatar Sep 05 '25 19:09 edward-simpson-byhiras