Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,33 @@ If performance matters to you:
has been made to make the performance impact minimal, but it
isn't nothing.

## Testing

When writing tests that involve TTL-related functionality, note that
this module creates an internal reference to the global
`performance` or `Date` objects at import time. If you import it
statically at the top level, those references cannot be mocked or
overridden in your test environment.

To avoid this, dynamically import the package within your tests so
that the references are captured after your mocks are applied. For
example:

```js
// ❌ Not recommended
import { LRUCache } from 'lru-cache'
// mocking timers, e.g. jest.useFakeTimers()

// ✅ Recommended for TTL tests
// mocking timers, e.g. jest.useFakeTimers()
const { LRUCache } = await import('lru-cache')
```

This ensures that your mocked timers or time sources are respected
when testing TTL behavior.



## Breaking Changes in Version 7

This library changed to a different algorithm and internal data
Expand Down