- Add observability features, expand the coverage of
LRUCache.Statusobjects.
- Add the
perfoption to specifyperformance,Date, or any other object with anow()method that returns a number.
- Add the
onInsertmethod
- Drop support for node less than v20
- Accidental minor update, should've been patch.
- add
forceFetch()method - set
disposeReasonto'expire'when it's the result of a TTL expiration, or'fetch'when it's the result of an aborted orundefined-returningfetch() - add
memo()method
- types: implement the
Map<K, V>interface
- add
cache.info(key)to get value as well as ttl and size information.
cache.fetch()return type is nowPromise<V | undefined>instead ofPromise<V | void>. This is an irrelevant change practically speaking, but can require changes for TypeScript users.
cache.set(key, undefined)is now an alias forcache.delete(key)
- Use named export only, no default export.
- Bring back minimal polyfill. If this polyfill ends up being used, then a warning is printed, as it is not safe for use outside of LRUCache.
- The
fetchContextoption was renamed tocontext, and may no longer be set on the cache instance itself. - Rewritten in TypeScript, so pretty much all the types moved around a lot.
- The AbortController/AbortSignal polyfill is removed. For this reason, Node version 16.14.0 or higher is now required.
- Internal properties were moved to actual private class properties.
- Keys and values must not be
nullorundefined. - Minified export available at
'lru-cache/min', for both CJS and MJS builds.
- Add support for internal state investigation through the use of
a
statusoption tohas(),set(),get(), andfetch().
- Add
signaloption forfetchto pass a user-supplied AbortSignal - Add
ignoreFetchAbortandallowStaleOnFetchAbortoptions
- Fail fetch() promises when they are aborted
- Add
allowStaleOnFetchRejectionoption
- Provide both ESM and CommonJS exports
- Add
maxEntrySizeoption to prevent caching items above a given calculated size.
- Add
forceRefreshoption to trigger a call to thefetchMethodeven if the item is found in cache, and not older than itsttl.
- Add
fetchContextoption to provide additional information to thefetchMethod - 7.12.1: Fix bug where adding an item with size greater than
maxSizewould cause bizarre behavior.
- Add 'noDeleteOnStaleGet' option, to suppress behavior where a
get()of a stale item would remove it from the cache.
- Add
noDeleteOnFetchRejectionoption, to suppress behavior where a failedfetchwill delete a previous stale value. - Ship types along with the package, rather than relying on out of date types coming from DefinitelyTyped.
- Better AbortController polyfill, supporting
signal.addEventListener('abort')andsignal.onabort. - (7.9.1) Drop item from cache instead of crashing with an
unhandledRejectionwhen thefetchMethodthrows an error or returns a rejected Promise.
- add
updateAgeOnHasoption - warnings sent to
console.errorifprocess.emitWarningunavailable
- fetch: provide options and abort signal
- add cache.getRemainingTTL(key)
- Add async cache.fetch() method, fetchMethod option
- Allow unbounded storage if maxSize or ttl set
- defend against mutation while iterating
- Add rentries, rkeys, rvalues
- remove bundler and unnecessary package.json fields
- Add browser optimized webpack bundle, exposed as
'lru-cache/browser' - Track size of compiled bundle in CI (@SuperOleg39)
- Add
noUpdateTTLoption forset()
- Add
disposeAfter() set()returns the cache objectdelete()returns boolean indicating whether anything was deleted
- Add reason to dispose() calls.
- Add
ttlResolutionoption - Add
ttlAutopurgeoption
This library changed to a different algorithm and internal data structure in version 7, yielding significantly better performance, albeit with some subtle changes as a result.
If you were relying on the internals of LRUCache in version 6 or before, it probably will not work in version 7 and above.
For the most part, the feature set has been maintained as much as possible.
However, some other cleanup and refactoring changes were made in v7 as well.
- The
set(),get(), andhas()functions take options objects instead of positional booleans/integers for optional parameters. sizecan be set explicitly onset().cache.lengthwas renamed to the more fittingcache.size.- Deprecations:
staleoption ->allowStalemaxAgeoption ->ttllengthoption ->sizeCalculationlengthproperty ->sizedel()method ->delete()prune()method ->purgeStale()reset()method ->clear()
- The objects used by
cache.load()andcache.dump()are incompatible with previous versions. maxandmaxSizeare now two separate options. (Previously, they were a singlemaxoption, which would be based on either count or computed size.)- The function assigned to the
disposeoption is now expected to have signature(value, key, reason)rather than(key, value), reversing the order ofvalueandkey.
- Drop support for node v8 and earlier
- Add updateAgeOnGet option
- Guards around setting max/maxAge to non-numbers
- Use classes, drop support for old nodes
- Improve performance
- add noDisposeOnSet option
- feat(prune): allow users to proactively prune old entries
- Use Symbols for private members
- Add maxAge setter/getter
- Add cache.rforEach
- Allow non-string keys
- add cache.pop()
- add cache.peek()
- add cache.keys()
- add cache.values()
- fix memory leak
- add
staleoption to return stale values before deleting - use null-prototype object to avoid hazards
- make options argument an object
- initial implementation