Skip to content

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

@domarmstrong

Description

@domarmstrong

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions