cloudstructs 0.9.10 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +3 -3
- package/assets/slack-textract/detect.lambda/index.js +2 -1
- package/lib/codecommit-mirror/index.js +2 -2
- package/lib/dmarc/index.js +1 -1
- package/lib/ecs-service-roller/index.js +2 -2
- package/lib/email-receiver/receiver.js +1 -1
- package/lib/mjml-template/index.js +1 -1
- package/lib/saml-identity-provider/index.js +2 -2
- package/lib/slack-app/manifest.js +1 -1
- package/lib/slack-app/slack-app.js +2 -2
- package/lib/slack-events/index.js +1 -1
- package/lib/slack-textract/index.js +1 -1
- package/lib/ssl-server-test/index.js +1 -1
- package/lib/state-machine-cr-provider/index.js +1 -1
- package/lib/static-website/index.js +1 -1
- package/lib/toolkit-cleaner/index.js +1 -1
- package/lib/url-shortener/index.js +1 -1
- package/node_modules/@babel/runtime/helpers/applyDecoratedDescriptor.js +1 -1
- package/node_modules/@babel/runtime/helpers/esm/applyDecoratedDescriptor.js +1 -1
- package/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js +2 -2
- package/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +1 -1
- package/node_modules/@babel/runtime/helpers/esm/superPropGet.js +9 -0
- package/node_modules/@babel/runtime/helpers/esm/superPropSet.js +6 -0
- package/node_modules/@babel/runtime/helpers/esm/usingCtx.js +36 -24
- package/node_modules/@babel/runtime/helpers/objectWithoutProperties.js +2 -2
- package/node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js +1 -1
- package/node_modules/@babel/runtime/helpers/superPropGet.js +9 -0
- package/node_modules/@babel/runtime/helpers/superPropSet.js +6 -0
- package/node_modules/@babel/runtime/helpers/usingCtx.js +36 -24
- package/node_modules/@babel/runtime/package.json +19 -1
- package/node_modules/@slack/logger/node_modules/@types/node/README.md +1 -1
- package/node_modules/@slack/logger/node_modules/@types/node/buffer.d.ts +0 -81
- package/node_modules/@slack/logger/node_modules/@types/node/child_process.d.ts +2 -2
- package/node_modules/@slack/logger/node_modules/@types/node/crypto.d.ts +5 -4
- package/node_modules/@slack/logger/node_modules/@types/node/dns/promises.d.ts +25 -23
- package/node_modules/@slack/logger/node_modules/@types/node/dns.d.ts +23 -23
- package/node_modules/@slack/logger/node_modules/@types/node/events.d.ts +11 -27
- package/node_modules/@slack/logger/node_modules/@types/node/package.json +3 -3
- package/node_modules/@slack/logger/node_modules/@types/node/test.d.ts +13 -2
- package/node_modules/@slack/web-api/node_modules/@types/node/README.md +1 -1
- package/node_modules/@slack/web-api/node_modules/@types/node/buffer.d.ts +0 -81
- package/node_modules/@slack/web-api/node_modules/@types/node/child_process.d.ts +2 -2
- package/node_modules/@slack/web-api/node_modules/@types/node/crypto.d.ts +5 -4
- package/node_modules/@slack/web-api/node_modules/@types/node/dns/promises.d.ts +25 -23
- package/node_modules/@slack/web-api/node_modules/@types/node/dns.d.ts +23 -23
- package/node_modules/@slack/web-api/node_modules/@types/node/events.d.ts +11 -27
- package/node_modules/@slack/web-api/node_modules/@types/node/package.json +3 -3
- package/node_modules/@slack/web-api/node_modules/@types/node/test.d.ts +13 -2
- package/node_modules/@types/cacheable-request/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/cacheable-request/node_modules/@types/node/buffer.d.ts +0 -81
- package/node_modules/@types/cacheable-request/node_modules/@types/node/child_process.d.ts +2 -2
- package/node_modules/@types/cacheable-request/node_modules/@types/node/crypto.d.ts +5 -4
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns/promises.d.ts +25 -23
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns.d.ts +23 -23
- package/node_modules/@types/cacheable-request/node_modules/@types/node/events.d.ts +11 -27
- package/node_modules/@types/cacheable-request/node_modules/@types/node/package.json +3 -3
- package/node_modules/@types/cacheable-request/node_modules/@types/node/test.d.ts +13 -2
- package/node_modules/@types/is-stream/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/is-stream/node_modules/@types/node/buffer.d.ts +0 -81
- package/node_modules/@types/is-stream/node_modules/@types/node/child_process.d.ts +2 -2
- package/node_modules/@types/is-stream/node_modules/@types/node/crypto.d.ts +5 -4
- package/node_modules/@types/is-stream/node_modules/@types/node/dns/promises.d.ts +25 -23
- package/node_modules/@types/is-stream/node_modules/@types/node/dns.d.ts +23 -23
- package/node_modules/@types/is-stream/node_modules/@types/node/events.d.ts +11 -27
- package/node_modules/@types/is-stream/node_modules/@types/node/package.json +3 -3
- package/node_modules/@types/is-stream/node_modules/@types/node/test.d.ts +13 -2
- package/node_modules/@types/keyv/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/keyv/node_modules/@types/node/buffer.d.ts +0 -81
- package/node_modules/@types/keyv/node_modules/@types/node/child_process.d.ts +2 -2
- package/node_modules/@types/keyv/node_modules/@types/node/crypto.d.ts +5 -4
- package/node_modules/@types/keyv/node_modules/@types/node/dns/promises.d.ts +25 -23
- package/node_modules/@types/keyv/node_modules/@types/node/dns.d.ts +23 -23
- package/node_modules/@types/keyv/node_modules/@types/node/events.d.ts +11 -27
- package/node_modules/@types/keyv/node_modules/@types/node/package.json +3 -3
- package/node_modules/@types/keyv/node_modules/@types/node/test.d.ts +13 -2
- package/node_modules/@types/responselike/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/responselike/node_modules/@types/node/buffer.d.ts +0 -81
- package/node_modules/@types/responselike/node_modules/@types/node/child_process.d.ts +2 -2
- package/node_modules/@types/responselike/node_modules/@types/node/crypto.d.ts +5 -4
- package/node_modules/@types/responselike/node_modules/@types/node/dns/promises.d.ts +25 -23
- package/node_modules/@types/responselike/node_modules/@types/node/dns.d.ts +23 -23
- package/node_modules/@types/responselike/node_modules/@types/node/events.d.ts +11 -27
- package/node_modules/@types/responselike/node_modules/@types/node/package.json +3 -3
- package/node_modules/@types/responselike/node_modules/@types/node/test.d.ts +13 -2
- package/node_modules/jackspeak/dist/commonjs/index.js +2 -2
- package/node_modules/jackspeak/dist/commonjs/index.js.map +1 -1
- package/node_modules/jackspeak/dist/esm/index.js +2 -2
- package/node_modules/jackspeak/dist/esm/index.js.map +1 -1
- package/node_modules/jackspeak/package.json +4 -4
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/glob.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/glob.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/ignore.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/ignore.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/index.d.ts +2 -2
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/index.js +6 -6
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/index.js.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/pattern.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/pattern.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/walker.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/commonjs/walker.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/glob.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/glob.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/ignore.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/ignore.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/index.d.ts +2 -2
- package/node_modules/js-beautify/node_modules/glob/dist/esm/pattern.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/pattern.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/walker.d.ts +0 -1
- package/node_modules/js-beautify/node_modules/glob/dist/esm/walker.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/glob/package.json +5 -4
- package/node_modules/js-beautify/node_modules/minimatch/README.md +1 -1
- package/node_modules/js-beautify/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/minimatch/dist/commonjs/index.js +5 -4
- package/node_modules/js-beautify/node_modules/minimatch/dist/commonjs/index.js.map +1 -1
- package/node_modules/js-beautify/node_modules/minimatch/dist/esm/index.d.ts.map +1 -1
- package/node_modules/js-beautify/node_modules/minimatch/dist/esm/index.js +5 -4
- package/node_modules/js-beautify/node_modules/minimatch/dist/esm/index.js.map +1 -1
- package/node_modules/js-beautify/node_modules/minimatch/package.json +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/glob.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/glob.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/ignore.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/ignore.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/index.d.ts +2 -2
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/index.js +6 -6
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/index.js.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/pattern.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/pattern.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/walker.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/commonjs/walker.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/glob.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/glob.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/ignore.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/ignore.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/index.d.ts +2 -2
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/pattern.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/pattern.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/walker.d.ts +0 -1
- package/node_modules/mjml-cli/node_modules/glob/dist/esm/walker.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/glob/package.json +5 -4
- package/node_modules/mjml-cli/node_modules/minimatch/README.md +1 -1
- package/node_modules/mjml-cli/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/minimatch/dist/commonjs/index.js +5 -4
- package/node_modules/mjml-cli/node_modules/minimatch/dist/commonjs/index.js.map +1 -1
- package/node_modules/mjml-cli/node_modules/minimatch/dist/esm/index.d.ts.map +1 -1
- package/node_modules/mjml-cli/node_modules/minimatch/dist/esm/index.js +5 -4
- package/node_modules/mjml-cli/node_modules/minimatch/dist/esm/index.js.map +1 -1
- package/node_modules/mjml-cli/node_modules/minimatch/package.json +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +11 -884
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts +486 -65
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +134 -34
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js.map +3 -3
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts +486 -65
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +134 -34
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js.map +3 -3
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +8 -9
- package/node_modules/semver/README.md +1 -1
- package/node_modules/semver/classes/range.js +24 -10
- package/node_modules/semver/package.json +1 -1
- package/node_modules/uglify-js/README.md +5 -5
- package/node_modules/uglify-js/lib/ast.js +5 -4
- package/node_modules/uglify-js/lib/compress.js +199 -84
- package/node_modules/uglify-js/lib/output.js +17 -4
- package/node_modules/uglify-js/package.json +1 -1
- package/package.json +20 -20
|
@@ -102,888 +102,8 @@ cache.clear() // empty the cache
|
|
|
102
102
|
If you put more stuff in the cache, then less recently used items
|
|
103
103
|
will fall out. That's what an LRU cache is.
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
Create a new `LRUCache` object.
|
|
108
|
-
|
|
109
|
-
When using TypeScript, set the `K` and `V` types to the `key` and
|
|
110
|
-
`value` types, respectively.
|
|
111
|
-
|
|
112
|
-
The `FC` ("fetch context") generic type defaults to `unknown`.
|
|
113
|
-
If set to a value other than `void` or `undefined`, then any
|
|
114
|
-
calls to `cache.fetch()` _must_ provide a `context` option
|
|
115
|
-
matching the `FC` type. If `FC` is set to `void` or `undefined`,
|
|
116
|
-
then `cache.fetch()` _must not_ provide a `context` option. See
|
|
117
|
-
the documentation on `async fetch()` below.
|
|
118
|
-
|
|
119
|
-
## Options
|
|
120
|
-
|
|
121
|
-
All options are available on the LRUCache instance, making it
|
|
122
|
-
safe to pass an LRUCache instance as the options argument to make
|
|
123
|
-
another empty cache of the same type.
|
|
124
|
-
|
|
125
|
-
Some options are marked read-only because changing them after
|
|
126
|
-
instantiation is not safe. Changing any of the other options
|
|
127
|
-
will of course only have an effect on subsequent method calls.
|
|
128
|
-
|
|
129
|
-
### `max` (read only)
|
|
130
|
-
|
|
131
|
-
The maximum number of items that remain in the cache (assuming no
|
|
132
|
-
TTL pruning or explicit deletions). Note that fewer items may be
|
|
133
|
-
stored if size calculation is used, and `maxSize` is exceeded.
|
|
134
|
-
This must be a positive finite intger.
|
|
135
|
-
|
|
136
|
-
At least one of `max`, `maxSize`, or `TTL` is required. This
|
|
137
|
-
must be a positive integer if set.
|
|
138
|
-
|
|
139
|
-
**It is strongly recommended to set a `max` to prevent unbounded
|
|
140
|
-
growth of the cache.** See "Storage Bounds Safety" below.
|
|
141
|
-
|
|
142
|
-
### `maxSize` (read only)
|
|
143
|
-
|
|
144
|
-
Set to a positive integer to track the sizes of items added to
|
|
145
|
-
the cache, and automatically evict items in order to stay below
|
|
146
|
-
this size. Note that this may result in fewer than `max` items
|
|
147
|
-
being stored.
|
|
148
|
-
|
|
149
|
-
Attempting to add an item to the cache whose calculated size is
|
|
150
|
-
greater that this amount will be a no-op. The item will not be
|
|
151
|
-
cached, and no other items will be evicted.
|
|
152
|
-
|
|
153
|
-
Optional, must be a positive integer if provided.
|
|
154
|
-
|
|
155
|
-
Sets `maxEntrySize` to the same value, unless a different value
|
|
156
|
-
is provided for `maxEntrySize`.
|
|
157
|
-
|
|
158
|
-
At least one of `max`, `maxSize`, or `TTL` is required. This
|
|
159
|
-
must be a positive integer if set.
|
|
160
|
-
|
|
161
|
-
Even if size tracking is enabled, **it is strongly recommended to
|
|
162
|
-
set a `max` to prevent unbounded growth of the cache.** See
|
|
163
|
-
"Storage Bounds Safety" below.
|
|
164
|
-
|
|
165
|
-
### `maxEntrySize`
|
|
166
|
-
|
|
167
|
-
Set to a positive integer to track the sizes of items added to
|
|
168
|
-
the cache, and prevent caching any item over a given size.
|
|
169
|
-
Attempting to add an item whose calculated size is greater than
|
|
170
|
-
this amount will be a no-op. The item will not be cached, and no
|
|
171
|
-
other items will be evicted.
|
|
172
|
-
|
|
173
|
-
Optional, must be a positive integer if provided. Defaults to
|
|
174
|
-
the value of `maxSize` if provided.
|
|
175
|
-
|
|
176
|
-
### `sizeCalculation`
|
|
177
|
-
|
|
178
|
-
Function used to calculate the size of stored items. If you're
|
|
179
|
-
storing strings or buffers, then you probably want to do
|
|
180
|
-
something like `n => n.length`. The item is passed as the first
|
|
181
|
-
argument, and the key is passed as the second argument.
|
|
182
|
-
|
|
183
|
-
This may be overridden by passing an options object to
|
|
184
|
-
`cache.set()`.
|
|
185
|
-
|
|
186
|
-
Requires `maxSize` to be set.
|
|
187
|
-
|
|
188
|
-
If the `size` (or return value of `sizeCalculation`) for a given
|
|
189
|
-
entry is greater than `maxEntrySize`, then the item will not be
|
|
190
|
-
added to the cache.
|
|
191
|
-
|
|
192
|
-
### `fetchMethod` (read only)
|
|
193
|
-
|
|
194
|
-
Function that is used to make background asynchronous fetches.
|
|
195
|
-
Called with `fetchMethod(key, staleValue, { signal, options,
|
|
196
|
-
context })`. May return a Promise.
|
|
197
|
-
|
|
198
|
-
If `fetchMethod` is not provided, then `cache.fetch(key)` is
|
|
199
|
-
equivalent to `Promise.resolve(cache.get(key))`.
|
|
200
|
-
|
|
201
|
-
If at any time, `signal.aborted` is set to `true`, or if the
|
|
202
|
-
`signal.onabort` method is called, or if it emits an `'abort'`
|
|
203
|
-
event which you can listen to with `addEventListener`, then that
|
|
204
|
-
means that the fetch should be abandoned. This may be passed
|
|
205
|
-
along to async functions aware of AbortController/AbortSignal
|
|
206
|
-
behavior.
|
|
207
|
-
|
|
208
|
-
The `fetchMethod` should **only** return `undefined` or a Promise
|
|
209
|
-
resolving to `undefined` if the AbortController signaled an
|
|
210
|
-
`abort` event. In all other cases, it should return or resolve
|
|
211
|
-
to a value suitable for adding to the cache.
|
|
212
|
-
|
|
213
|
-
The `options` object is a union of the options that may be
|
|
214
|
-
provided to `set()` and `get()`. If they are modified, then that
|
|
215
|
-
will result in modifying the settings to `cache.set()` when the
|
|
216
|
-
value is resolved, and in the case of `noDeleteOnFetchRejection`
|
|
217
|
-
and `allowStaleOnFetchRejection`, the handling of `fetchMethod`
|
|
218
|
-
failures.
|
|
219
|
-
|
|
220
|
-
For example, a DNS cache may update the TTL based on the value
|
|
221
|
-
returned from a remote DNS server by changing `options.ttl` in
|
|
222
|
-
the `fetchMethod`.
|
|
223
|
-
|
|
224
|
-
### `noDeleteOnFetchRejection`
|
|
225
|
-
|
|
226
|
-
If a `fetchMethod` throws an error or returns a rejected promise,
|
|
227
|
-
then by default, any existing stale value will be removed from
|
|
228
|
-
the cache.
|
|
229
|
-
|
|
230
|
-
If `noDeleteOnFetchRejection` is set to `true`, then this
|
|
231
|
-
behavior is suppressed, and the stale value remains in the cache
|
|
232
|
-
in the case of a rejected `fetchMethod`.
|
|
233
|
-
|
|
234
|
-
This is important in cases where a `fetchMethod` is _only_ called
|
|
235
|
-
as a background update while the stale value is returned, when
|
|
236
|
-
`allowStale` is used.
|
|
237
|
-
|
|
238
|
-
This is implicitly in effect when `allowStaleOnFetchRejection` is
|
|
239
|
-
set.
|
|
240
|
-
|
|
241
|
-
This may be set in calls to `fetch()`, or defaulted on the
|
|
242
|
-
constructor, or overridden by modifying the options object in the
|
|
243
|
-
`fetchMethod`.
|
|
244
|
-
|
|
245
|
-
### `allowStaleOnFetchRejection`
|
|
246
|
-
|
|
247
|
-
Set to true to return a stale value from the cache when a
|
|
248
|
-
`fetchMethod` throws an error or returns a rejected Promise.
|
|
249
|
-
|
|
250
|
-
If a `fetchMethod` fails, and there is no stale value available,
|
|
251
|
-
the `fetch()` will resolve to `undefined`. Ie, all `fetchMethod`
|
|
252
|
-
errors are suppressed.
|
|
253
|
-
|
|
254
|
-
Implies `noDeleteOnFetchRejection`.
|
|
255
|
-
|
|
256
|
-
This may be set in calls to `fetch()`, or defaulted on the
|
|
257
|
-
constructor, or overridden by modifying the options object in the
|
|
258
|
-
`fetchMethod`.
|
|
259
|
-
|
|
260
|
-
### `allowStaleOnFetchAbort`
|
|
261
|
-
|
|
262
|
-
Set to true to return a stale value from the cache when the
|
|
263
|
-
`AbortSignal` passed to the `fetchMethod` dispatches an `'abort'`
|
|
264
|
-
event, whether user-triggered, or due to internal cache behavior.
|
|
265
|
-
|
|
266
|
-
Unless `ignoreFetchAbort` is also set, the underlying
|
|
267
|
-
`fetchMethod` will still be considered canceled, and any value
|
|
268
|
-
it returns will be ignored and not cached.
|
|
269
|
-
|
|
270
|
-
Caveat: since fetches are aborted when a new value is explicitly
|
|
271
|
-
set in the cache, this can lead to fetch returning a stale value,
|
|
272
|
-
since that was the fallback value _at the moment the `fetch()` was
|
|
273
|
-
initiated_, even though the new updated value is now present in
|
|
274
|
-
the cache.
|
|
275
|
-
|
|
276
|
-
For example:
|
|
277
|
-
|
|
278
|
-
```ts
|
|
279
|
-
const cache = new LRUCache<string, any>({
|
|
280
|
-
ttl: 100,
|
|
281
|
-
fetchMethod: async (url, oldValue, { signal }) => {
|
|
282
|
-
const res = await fetch(url, { signal })
|
|
283
|
-
return await res.json()
|
|
284
|
-
},
|
|
285
|
-
})
|
|
286
|
-
cache.set('https://example.com/', { some: 'data' })
|
|
287
|
-
// 100ms go by...
|
|
288
|
-
const result = cache.fetch('https://example.com/')
|
|
289
|
-
cache.set('https://example.com/', { other: 'thing' })
|
|
290
|
-
console.log(await result) // { some: 'data' }
|
|
291
|
-
console.log(cache.get('https://example.com/')) // { other: 'thing' }
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### `ignoreFetchAbort`
|
|
295
|
-
|
|
296
|
-
Set to true to ignore the `abort` event emitted by the
|
|
297
|
-
`AbortSignal` object passed to `fetchMethod`, and still cache the
|
|
298
|
-
resulting resolution value, as long as it is not `undefined`.
|
|
299
|
-
|
|
300
|
-
When used on its own, this means aborted `fetch()` calls are not
|
|
301
|
-
immediately resolved or rejected when they are aborted, and
|
|
302
|
-
instead take the full time to await.
|
|
303
|
-
|
|
304
|
-
When used with `allowStaleOnFetchAbort`, aborted `fetch()` calls
|
|
305
|
-
will resolve immediately to their stale cached value or
|
|
306
|
-
`undefined`, and will continue to process and eventually update
|
|
307
|
-
the cache when they resolve, as long as the resulting value is
|
|
308
|
-
not `undefined`, thus supporting a "return stale on timeout while
|
|
309
|
-
refreshing" mechanism by passing `AbortSignal.timeout(n)` as the
|
|
310
|
-
signal.
|
|
311
|
-
|
|
312
|
-
For example:
|
|
313
|
-
|
|
314
|
-
```js
|
|
315
|
-
const c = new LRUCache({
|
|
316
|
-
ttl: 100,
|
|
317
|
-
ignoreFetchAbort: true,
|
|
318
|
-
allowStaleOnFetchAbort: true,
|
|
319
|
-
fetchMethod: async (key, oldValue, { signal }) => {
|
|
320
|
-
// note: do NOT pass the signal to fetch()!
|
|
321
|
-
// let's say this fetch can take a long time.
|
|
322
|
-
const res = await fetch(`https://slow-backend-server/${key}`)
|
|
323
|
-
return await res.json()
|
|
324
|
-
},
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
// this will return the stale value after 100ms, while still
|
|
328
|
-
// updating in the background for next time.
|
|
329
|
-
const val = await c.fetch('key', { signal: AbortSignal.timeout(100) })
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
**Note**: regardless of this setting, an `abort` event _is still
|
|
333
|
-
emitted on the `AbortSignal` object_, so may result in invalid
|
|
334
|
-
results when passed to other underlying APIs that use
|
|
335
|
-
AbortSignals.
|
|
336
|
-
|
|
337
|
-
This may be overridden on the `fetch()` call or in the
|
|
338
|
-
`fetchMethod` itself.
|
|
339
|
-
|
|
340
|
-
### `dispose` (read only)
|
|
341
|
-
|
|
342
|
-
Function that is called on items when they are dropped from the
|
|
343
|
-
cache, as `this.dispose(value, key, reason)`.
|
|
344
|
-
|
|
345
|
-
This can be handy if you want to close file descriptors or do
|
|
346
|
-
other cleanup tasks when items are no longer stored in the cache.
|
|
347
|
-
|
|
348
|
-
**NOTE**: It is called _before_ the item has been fully removed
|
|
349
|
-
from the cache, so if you want to put it right back in, you need
|
|
350
|
-
to wait until the next tick. If you try to add it back in during
|
|
351
|
-
the `dispose()` function call, it will break things in subtle and
|
|
352
|
-
weird ways.
|
|
353
|
-
|
|
354
|
-
Unlike several other options, this may _not_ be overridden by
|
|
355
|
-
passing an option to `set()`, for performance reasons.
|
|
356
|
-
|
|
357
|
-
The `reason` will be one of the following strings, corresponding
|
|
358
|
-
to the reason for the item's deletion:
|
|
359
|
-
|
|
360
|
-
- `evict` Item was evicted to make space for a new addition
|
|
361
|
-
- `set` Item was overwritten by a new value
|
|
362
|
-
- `delete` Item was removed by explicit `cache.delete(key)` or by
|
|
363
|
-
calling `cache.clear()`, which deletes everything.
|
|
364
|
-
|
|
365
|
-
The `dispose()` method is _not_ called for canceled calls to
|
|
366
|
-
`fetchMethod()`. If you wish to handle evictions, overwrites,
|
|
367
|
-
and deletes of in-flight asynchronous fetches, you must use the
|
|
368
|
-
`AbortSignal` provided.
|
|
369
|
-
|
|
370
|
-
Optional, must be a function.
|
|
371
|
-
|
|
372
|
-
### `disposeAfter` (read only)
|
|
373
|
-
|
|
374
|
-
The same as `dispose`, but called _after_ the entry is completely
|
|
375
|
-
removed and the cache is once again in a clean state.
|
|
376
|
-
|
|
377
|
-
It is safe to add an item right back into the cache at this
|
|
378
|
-
point. However, note that it is _very_ easy to inadvertently
|
|
379
|
-
create infinite recursion in this way.
|
|
380
|
-
|
|
381
|
-
The `disposeAfter()` method is _not_ called for canceled calls to
|
|
382
|
-
`fetchMethod()`. If you wish to handle evictions, overwrites,
|
|
383
|
-
and deletes of in-flight asynchronous fetches, you must use the
|
|
384
|
-
`AbortSignal` provided.
|
|
385
|
-
|
|
386
|
-
### `noDisposeOnSet`
|
|
387
|
-
|
|
388
|
-
Set to `true` to suppress calling the `dispose()` function if the
|
|
389
|
-
entry key is still accessible within the cache.
|
|
390
|
-
|
|
391
|
-
This may be overridden by passing an options object to
|
|
392
|
-
`cache.set()`.
|
|
393
|
-
|
|
394
|
-
Boolean, default `false`. Only relevant if `dispose` or
|
|
395
|
-
`disposeAfter` options are set.
|
|
396
|
-
|
|
397
|
-
### `ttl`
|
|
398
|
-
|
|
399
|
-
Max time to live for items before they are considered stale.
|
|
400
|
-
Note that stale items are NOT preemptively removed by default,
|
|
401
|
-
and MAY live in the cache, contributing to its LRU max, long
|
|
402
|
-
after they have expired.
|
|
403
|
-
|
|
404
|
-
Also, as this cache is optimized for LRU/MRU operations, some of
|
|
405
|
-
the staleness/TTL checks will reduce performance.
|
|
406
|
-
|
|
407
|
-
This is not primarily a TTL cache, and does not make strong TTL
|
|
408
|
-
guarantees. There is no pre-emptive pruning of expired items,
|
|
409
|
-
but you _may_ set a TTL on the cache, and it will treat expired
|
|
410
|
-
items as missing when they are fetched, and delete them.
|
|
411
|
-
|
|
412
|
-
Optional, but must be a positive integer in ms if specified.
|
|
413
|
-
|
|
414
|
-
This may be overridden by passing an options object to
|
|
415
|
-
`cache.set()`.
|
|
416
|
-
|
|
417
|
-
At least one of `max`, `maxSize`, or `TTL` is required. This
|
|
418
|
-
must be a positive integer if set.
|
|
419
|
-
|
|
420
|
-
Even if ttl tracking is enabled, **it is strongly recommended to
|
|
421
|
-
set a `max` to prevent unbounded growth of the cache.** See
|
|
422
|
-
"Storage Bounds Safety" below.
|
|
423
|
-
|
|
424
|
-
If ttl tracking is enabled, and `max` and `maxSize` are not set,
|
|
425
|
-
and `ttlAutopurge` is not set, then a warning will be emitted
|
|
426
|
-
cautioning about the potential for unbounded memory consumption.
|
|
427
|
-
(The TypeScript definitions will also discourage this.)
|
|
428
|
-
|
|
429
|
-
### `noUpdateTTL`
|
|
430
|
-
|
|
431
|
-
Boolean flag to tell the cache to not update the TTL when setting
|
|
432
|
-
a new value for an existing key (ie, when updating a value rather
|
|
433
|
-
than inserting a new value). Note that the TTL value is _always_
|
|
434
|
-
set (if provided) when adding a new entry into the cache.
|
|
435
|
-
|
|
436
|
-
This may be passed as an option to `cache.set()`.
|
|
437
|
-
|
|
438
|
-
Boolean, default false.
|
|
439
|
-
|
|
440
|
-
### `ttlResolution`
|
|
441
|
-
|
|
442
|
-
Minimum amount of time in ms in which to check for staleness.
|
|
443
|
-
Defaults to `1`, which means that the current time is checked at
|
|
444
|
-
most once per millisecond.
|
|
445
|
-
|
|
446
|
-
Set to `0` to check the current time every time staleness is
|
|
447
|
-
tested.
|
|
448
|
-
|
|
449
|
-
Note that setting this to a higher value _will_ improve
|
|
450
|
-
performance somewhat while using ttl tracking, albeit at the
|
|
451
|
-
expense of keeping stale items around a bit longer than intended.
|
|
452
|
-
|
|
453
|
-
### `ttlAutopurge`
|
|
454
|
-
|
|
455
|
-
Preemptively remove stale items from the cache.
|
|
456
|
-
|
|
457
|
-
Note that this may _significantly_ degrade performance,
|
|
458
|
-
especially if the cache is storing a large number of items. It
|
|
459
|
-
is almost always best to just leave the stale items in the cache,
|
|
460
|
-
and let them fall out as new items are added.
|
|
461
|
-
|
|
462
|
-
Note that this means that `allowStale` is a bit pointless, as
|
|
463
|
-
stale items will be deleted almost as soon as they expire.
|
|
464
|
-
|
|
465
|
-
Use with caution!
|
|
466
|
-
|
|
467
|
-
Boolean, default `false`
|
|
468
|
-
|
|
469
|
-
### `allowStale`
|
|
470
|
-
|
|
471
|
-
By default, if you set `ttl`, it'll only delete stale items from
|
|
472
|
-
the cache when you `get(key)`. That is, it's not preemptively
|
|
473
|
-
pruning items.
|
|
474
|
-
|
|
475
|
-
If you set `allowStale:true`, it'll return the stale value as
|
|
476
|
-
well as deleting it. If you don't set this, then it'll return
|
|
477
|
-
`undefined` when you try to get a stale entry.
|
|
478
|
-
|
|
479
|
-
Note that when a stale entry is fetched, _even if it is returned
|
|
480
|
-
due to `allowStale` being set_, it is removed from the cache
|
|
481
|
-
immediately. You can immediately put it back in the cache if you
|
|
482
|
-
wish, thus resetting the TTL.
|
|
483
|
-
|
|
484
|
-
This may be overridden by passing an options object to
|
|
485
|
-
`cache.get()`. The `cache.has()` method will always return
|
|
486
|
-
`false` for stale items.
|
|
487
|
-
|
|
488
|
-
Boolean, default false, only relevant if `ttl` is set.
|
|
489
|
-
|
|
490
|
-
### `noDeleteOnStaleGet`
|
|
491
|
-
|
|
492
|
-
When using time-expiring entries with `ttl`, by default stale
|
|
493
|
-
items will be removed from the cache when the key is accessed
|
|
494
|
-
with `cache.get()`.
|
|
495
|
-
|
|
496
|
-
Setting `noDeleteOnStaleGet` to `true` will cause stale items to
|
|
497
|
-
remain in the cache, until they are explicitly deleted with
|
|
498
|
-
`cache.delete(key)`, or retrieved with `noDeleteOnStaleGet` set
|
|
499
|
-
to `false`.
|
|
500
|
-
|
|
501
|
-
This may be overridden by passing an options object to
|
|
502
|
-
`cache.get()`.
|
|
503
|
-
|
|
504
|
-
Boolean, default false, only relevant if `ttl` is set.
|
|
505
|
-
|
|
506
|
-
### `updateAgeOnGet`
|
|
507
|
-
|
|
508
|
-
When using time-expiring entries with `ttl`, setting this to
|
|
509
|
-
`true` will make each item's age reset to 0 whenever it is
|
|
510
|
-
retrieved from cache with `get()`, causing it to not expire. (It
|
|
511
|
-
can still fall out of cache based on recency of use, of course.)
|
|
512
|
-
|
|
513
|
-
This may be overridden by passing an options object to
|
|
514
|
-
`cache.get()`.
|
|
515
|
-
|
|
516
|
-
Boolean, default false, only relevant if `ttl` is set.
|
|
517
|
-
|
|
518
|
-
### `updateAgeOnHas`
|
|
519
|
-
|
|
520
|
-
When using time-expiring entries with `ttl`, setting this to
|
|
521
|
-
`true` will make each item's age reset to 0 whenever its presence
|
|
522
|
-
in the cache is checked with `has()`, causing it to not expire.
|
|
523
|
-
(It can still fall out of cache based on recency of use, of
|
|
524
|
-
course.)
|
|
525
|
-
|
|
526
|
-
This may be overridden by passing an options object to
|
|
527
|
-
`cache.has()`.
|
|
528
|
-
|
|
529
|
-
Boolean, default false, only relevant if `ttl` is set.
|
|
530
|
-
|
|
531
|
-
## API
|
|
532
|
-
|
|
533
|
-
### `new LRUCache<K, V, FC = unknown>(options)`
|
|
534
|
-
|
|
535
|
-
Create a new LRUCache. All options are documented above, and are
|
|
536
|
-
on the cache as public members.
|
|
537
|
-
|
|
538
|
-
The `K` and `V` types define the key and value types,
|
|
539
|
-
respectively. The optional `FC` type defines the type of the
|
|
540
|
-
`context` object passed to `cache.fetch()`.
|
|
541
|
-
|
|
542
|
-
Keys and values **must not** be `null` or `undefined`.
|
|
543
|
-
|
|
544
|
-
### `cache.max`, `cache.maxSize`, `cache.allowStale`,
|
|
545
|
-
|
|
546
|
-
`cache.noDisposeOnSet`, `cache.sizeCalculation`, `cache.dispose`,
|
|
547
|
-
`cache.maxSize`, `cache.ttl`, `cache.updateAgeOnGet`,
|
|
548
|
-
`cache.updateAgeOnHas`
|
|
549
|
-
|
|
550
|
-
All option names are exposed as public members on the cache
|
|
551
|
-
object.
|
|
552
|
-
|
|
553
|
-
These are intended for read access only. Changing them during
|
|
554
|
-
program operation can cause undefined behavior.
|
|
555
|
-
|
|
556
|
-
### `cache.size`
|
|
557
|
-
|
|
558
|
-
The total number of items held in the cache at the current
|
|
559
|
-
moment.
|
|
560
|
-
|
|
561
|
-
### `cache.calculatedSize`
|
|
562
|
-
|
|
563
|
-
The total size of items in cache when using size tracking.
|
|
564
|
-
|
|
565
|
-
### `set(key, value, [{ size, sizeCalculation, ttl, noDisposeOnSet, start, status }])`
|
|
566
|
-
|
|
567
|
-
Add a value to the cache.
|
|
568
|
-
|
|
569
|
-
Optional options object may contain `ttl` and `sizeCalculation`
|
|
570
|
-
as described above, which default to the settings on the cache
|
|
571
|
-
object.
|
|
572
|
-
|
|
573
|
-
If `start` is provided, then that will set the effective start
|
|
574
|
-
time for the TTL calculation. Note that this must be a previous
|
|
575
|
-
value of `performance.now()` if supported, or a previous value of
|
|
576
|
-
`Date.now()` if not.
|
|
577
|
-
|
|
578
|
-
Options object may also include `size`, which will prevent
|
|
579
|
-
calling the `sizeCalculation` function and just use the specified
|
|
580
|
-
number if it is a positive integer, and `noDisposeOnSet` which
|
|
581
|
-
will prevent calling a `dispose` function in the case of
|
|
582
|
-
overwrites.
|
|
583
|
-
|
|
584
|
-
If the `size` (or return value of `sizeCalculation`) for a given
|
|
585
|
-
entry is greater than `maxEntrySize`, then the item will not be
|
|
586
|
-
added to the cache.
|
|
587
|
-
|
|
588
|
-
Will update the recency of the entry.
|
|
589
|
-
|
|
590
|
-
Returns the cache object.
|
|
591
|
-
|
|
592
|
-
For the usage of the `status` option, see **Status Tracking**
|
|
593
|
-
below.
|
|
594
|
-
|
|
595
|
-
If the value is `undefined`, then this is an alias for
|
|
596
|
-
`cache.delete(key)`. `undefined` is never stored in the cache.
|
|
597
|
-
See **Storing Undefined Values** below.
|
|
598
|
-
|
|
599
|
-
### `get(key, { updateAgeOnGet, allowStale, status } = {}) => value`
|
|
600
|
-
|
|
601
|
-
Return a value from the cache.
|
|
602
|
-
|
|
603
|
-
Will update the recency of the cache entry found.
|
|
604
|
-
|
|
605
|
-
If the key is not found, `get()` will return `undefined`.
|
|
606
|
-
|
|
607
|
-
For the usage of the `status` option, see **Status Tracking**
|
|
608
|
-
below.
|
|
609
|
-
|
|
610
|
-
### `info(key) => Entry | undefined`
|
|
611
|
-
|
|
612
|
-
Return an `Entry` object containing the currently cached value,
|
|
613
|
-
as well as ttl and size information if available. Returns
|
|
614
|
-
undefined if the key is not found in the cache.
|
|
615
|
-
|
|
616
|
-
Unlike `dump()` (which is designed to be portable and survive
|
|
617
|
-
serialization), the `start` value is always the current
|
|
618
|
-
timestamp, and the `ttl` is a calculated remaining time to live
|
|
619
|
-
(negative if expired).
|
|
620
|
-
|
|
621
|
-
Note that stale values are always returned, rather than being
|
|
622
|
-
pruned and treated as if they were not in the cache. If you wish
|
|
623
|
-
to exclude stale entries, guard against a negative `ttl` value.
|
|
624
|
-
|
|
625
|
-
### `async fetch(key, options = {}) => Promise`
|
|
626
|
-
|
|
627
|
-
The following options are supported:
|
|
628
|
-
|
|
629
|
-
- `updateAgeOnGet`
|
|
630
|
-
- `allowStale`
|
|
631
|
-
- `size`
|
|
632
|
-
- `sizeCalculation`
|
|
633
|
-
- `ttl`
|
|
634
|
-
- `noDisposeOnSet`
|
|
635
|
-
- `forceRefresh`
|
|
636
|
-
- `status` - See **Status Tracking** below.
|
|
637
|
-
- `signal` - AbortSignal can be used to cancel the `fetch()`.
|
|
638
|
-
Note that the `signal` option provided to the `fetchMethod` is
|
|
639
|
-
a different object, because it must also respond to internal
|
|
640
|
-
cache state changes, but aborting this signal will abort the
|
|
641
|
-
one passed to `fetchMethod` as well.
|
|
642
|
-
- `context` - sets the `context` option passed to the underlying
|
|
643
|
-
`fetchMethod`.
|
|
644
|
-
|
|
645
|
-
If the value is in the cache and not stale, then the returned
|
|
646
|
-
Promise resolves to the value.
|
|
647
|
-
|
|
648
|
-
If not in the cache, or beyond its TTL staleness, then
|
|
649
|
-
`fetchMethod(key, staleValue, { options, signal, context })` is
|
|
650
|
-
called, and the value returned will be added to the cache once
|
|
651
|
-
resolved.
|
|
652
|
-
|
|
653
|
-
If called with `allowStale`, and an asynchronous fetch is
|
|
654
|
-
currently in progress to reload a stale value, then the former
|
|
655
|
-
stale value will be returned.
|
|
656
|
-
|
|
657
|
-
If called with `forceRefresh`, then the cached item will be
|
|
658
|
-
re-fetched, even if it is not stale. However, if `allowStale` is
|
|
659
|
-
set, then the old value will still be returned. This is useful
|
|
660
|
-
in cases where you want to force a reload of a cached value. If
|
|
661
|
-
a background fetch is already in progress, then `forceRefresh`
|
|
662
|
-
has no effect.
|
|
663
|
-
|
|
664
|
-
Multiple fetches for the same `key` will only call `fetchMethod`
|
|
665
|
-
a single time, and all will be resolved when the value is
|
|
666
|
-
resolved, even if different options are used.
|
|
667
|
-
|
|
668
|
-
If `fetchMethod` is not specified, then this is effectively an
|
|
669
|
-
alias for `Promise.resolve(cache.get(key))`.
|
|
670
|
-
|
|
671
|
-
When the fetch method resolves to a value, if the fetch has not
|
|
672
|
-
been aborted due to deletion, eviction, or being overwritten,
|
|
673
|
-
then it is added to the cache using the options provided.
|
|
674
|
-
|
|
675
|
-
If the key is evicted or deleted before the `fetchMethod`
|
|
676
|
-
resolves, then the AbortSignal passed to the `fetchMethod` will
|
|
677
|
-
receive an `abort` event, and the promise returned by `fetch()`
|
|
678
|
-
will reject with the reason for the abort.
|
|
679
|
-
|
|
680
|
-
If a `signal` is passed to the `fetch()` call, then aborting the
|
|
681
|
-
signal will abort the fetch and cause the `fetch()` promise to
|
|
682
|
-
reject with the reason provided.
|
|
683
|
-
|
|
684
|
-
#### Setting `context`
|
|
685
|
-
|
|
686
|
-
If an `FC` type is set to a type other than `unknown`, `void`, or
|
|
687
|
-
`undefined` in the LRUCache constructor, then all
|
|
688
|
-
calls to `cache.fetch()` _must_ provide a `context` option. If
|
|
689
|
-
set to `undefined` or `void`, then calls to fetch _must not_
|
|
690
|
-
provide a `context` option.
|
|
691
|
-
|
|
692
|
-
The `context` param allows you to provide arbitrary data that
|
|
693
|
-
might be relevant in the course of fetching the data. It is only
|
|
694
|
-
relevant for the course of a single `fetch()` operation, and
|
|
695
|
-
discarded afterwards.
|
|
696
|
-
|
|
697
|
-
#### Note: `fetch()` calls are inflight-unique
|
|
698
|
-
|
|
699
|
-
If you call `fetch()` multiple times with the same key value,
|
|
700
|
-
then every call after the first will resolve on the same
|
|
701
|
-
promise<sup>1</sup>,
|
|
702
|
-
_even if they have different settings that would otherwise change
|
|
703
|
-
the behvavior of the fetch_, such as `noDeleteOnFetchRejection`
|
|
704
|
-
or `ignoreFetchAbort`.
|
|
705
|
-
|
|
706
|
-
In most cases, this is not a problem (in fact, only fetching
|
|
707
|
-
something once is what you probably want, if you're caching in
|
|
708
|
-
the first place). If you are changing the fetch() options
|
|
709
|
-
dramatically between runs, there's a good chance that you might
|
|
710
|
-
be trying to fit divergent semantics into a single object, and
|
|
711
|
-
would be better off with multiple cache instances.
|
|
712
|
-
|
|
713
|
-
**1**: Ie, they're not the "same Promise", but they resolve at
|
|
714
|
-
the same time, because they're both waiting on the same
|
|
715
|
-
underlying fetchMethod response.
|
|
716
|
-
|
|
717
|
-
### `peek(key, { allowStale } = {}) => value`
|
|
718
|
-
|
|
719
|
-
Like `get()` but doesn't update recency or delete stale items.
|
|
720
|
-
|
|
721
|
-
Returns `undefined` if the item is stale, unless `allowStale` is
|
|
722
|
-
set either on the cache or in the options object.
|
|
723
|
-
|
|
724
|
-
### `has(key, { updateAgeOnHas, status } = {}) => Boolean`
|
|
725
|
-
|
|
726
|
-
Check if a key is in the cache, without updating the recency of
|
|
727
|
-
use. Age is updated if `updateAgeOnHas` is set to `true` in
|
|
728
|
-
either the options or the constructor.
|
|
729
|
-
|
|
730
|
-
Will return `false` if the item is stale, even though it is
|
|
731
|
-
technically in the cache. The difference can be determined (if
|
|
732
|
-
it matters) by using a `status` argument, and inspecting the
|
|
733
|
-
`has` field.
|
|
734
|
-
|
|
735
|
-
For the usage of the `status` option, see **Status Tracking**
|
|
736
|
-
below.
|
|
737
|
-
|
|
738
|
-
### `delete(key)`
|
|
739
|
-
|
|
740
|
-
Deletes a key out of the cache.
|
|
741
|
-
|
|
742
|
-
Returns `true` if the key was deleted, `false` otherwise.
|
|
743
|
-
|
|
744
|
-
### `clear()`
|
|
745
|
-
|
|
746
|
-
Clear the cache entirely, throwing away all values.
|
|
747
|
-
|
|
748
|
-
### `keys()`
|
|
749
|
-
|
|
750
|
-
Return a generator yielding the keys in the cache, in order from
|
|
751
|
-
most recently used to least recently used.
|
|
752
|
-
|
|
753
|
-
### `rkeys()`
|
|
754
|
-
|
|
755
|
-
Return a generator yielding the keys in the cache, in order from
|
|
756
|
-
least recently used to most recently used.
|
|
757
|
-
|
|
758
|
-
### `values()`
|
|
759
|
-
|
|
760
|
-
Return a generator yielding the values in the cache, in order
|
|
761
|
-
from most recently used to least recently used.
|
|
762
|
-
|
|
763
|
-
### `rvalues()`
|
|
764
|
-
|
|
765
|
-
Return a generator yielding the values in the cache, in order
|
|
766
|
-
from least recently used to most recently used.
|
|
767
|
-
|
|
768
|
-
### `entries()`
|
|
769
|
-
|
|
770
|
-
Return a generator yielding `[key, value]` pairs, in order from
|
|
771
|
-
most recently used to least recently used.
|
|
772
|
-
|
|
773
|
-
### `rentries()`
|
|
774
|
-
|
|
775
|
-
Return a generator yielding `[key, value]` pairs, in order from
|
|
776
|
-
least recently used to most recently used.
|
|
777
|
-
|
|
778
|
-
### `find(fn, [getOptions])`
|
|
779
|
-
|
|
780
|
-
Find a value for which the supplied `fn` method returns a truthy
|
|
781
|
-
value, similar to `Array.find()`.
|
|
782
|
-
|
|
783
|
-
`fn` is called as `fn(value, key, cache)`.
|
|
784
|
-
|
|
785
|
-
The optional `getOptions` are applied to the resulting `get()` of
|
|
786
|
-
the item found.
|
|
787
|
-
|
|
788
|
-
### `dump()`
|
|
789
|
-
|
|
790
|
-
Return an array of `[key, entry]` objects which can be passed to
|
|
791
|
-
`cache.load()`
|
|
792
|
-
|
|
793
|
-
The `start` fields are calculated relative to a portable
|
|
794
|
-
`Date.now()` timestamp, even if `performance.now()` is available.
|
|
795
|
-
|
|
796
|
-
Stale entries are always included in the `dump`, even if
|
|
797
|
-
`allowStale` is false.
|
|
798
|
-
|
|
799
|
-
Note: this returns an actual array, not a generator, so it can be
|
|
800
|
-
more easily passed around.
|
|
801
|
-
|
|
802
|
-
### `load(entries)`
|
|
803
|
-
|
|
804
|
-
Reset the cache and load in the items in `entries` in the order
|
|
805
|
-
listed. Note that the shape of the resulting cache may be
|
|
806
|
-
different if the same options are not used in both caches.
|
|
807
|
-
|
|
808
|
-
The `start` fields are assumed to be calculated relative to a
|
|
809
|
-
portable `Date.now()` timestamp, even if `performance.now()` is
|
|
810
|
-
available.
|
|
811
|
-
|
|
812
|
-
### `purgeStale()`
|
|
813
|
-
|
|
814
|
-
Delete any stale entries. Returns `true` if anything was
|
|
815
|
-
removed, `false` otherwise.
|
|
816
|
-
|
|
817
|
-
### `getRemainingTTL(key)`
|
|
818
|
-
|
|
819
|
-
Return the number of ms left in the item's TTL. If item is not
|
|
820
|
-
in cache, returns `0`. Returns `Infinity` if item is in cache
|
|
821
|
-
without a defined TTL.
|
|
822
|
-
|
|
823
|
-
### `forEach(fn, [thisp])`
|
|
824
|
-
|
|
825
|
-
Call the `fn` function with each set of `fn(value, key, cache)`
|
|
826
|
-
in the LRU cache, from most recent to least recently used.
|
|
827
|
-
|
|
828
|
-
Does not affect recency of use.
|
|
829
|
-
|
|
830
|
-
If `thisp` is provided, function will be called in the
|
|
831
|
-
`this`-context of the provided object.
|
|
832
|
-
|
|
833
|
-
### `rforEach(fn, [thisp])`
|
|
834
|
-
|
|
835
|
-
Same as `cache.forEach(fn, thisp)`, but in order from least
|
|
836
|
-
recently used to most recently used.
|
|
837
|
-
|
|
838
|
-
### `pop()`
|
|
839
|
-
|
|
840
|
-
Evict the least recently used item, returning its value.
|
|
841
|
-
|
|
842
|
-
Returns `undefined` if cache is empty.
|
|
843
|
-
|
|
844
|
-
## Status Tracking
|
|
845
|
-
|
|
846
|
-
Occasionally, it may be useful to track the internal behavior of
|
|
847
|
-
the cache, particularly for logging, debugging, or for behavior
|
|
848
|
-
within the `fetchMethod`. To do this, you can pass a `status`
|
|
849
|
-
object to the `get()`, `set()`, `has()`, and `fetch()` methods.
|
|
850
|
-
|
|
851
|
-
The `status` option should be a plain JavaScript object.
|
|
852
|
-
|
|
853
|
-
The following fields will be set appropriately:
|
|
854
|
-
|
|
855
|
-
```ts
|
|
856
|
-
interface Status<V> {
|
|
857
|
-
/**
|
|
858
|
-
* The status of a set() operation.
|
|
859
|
-
*
|
|
860
|
-
* - add: the item was not found in the cache, and was added
|
|
861
|
-
* - update: the item was in the cache, with the same value provided
|
|
862
|
-
* - replace: the item was in the cache, and replaced
|
|
863
|
-
* - miss: the item was not added to the cache for some reason
|
|
864
|
-
*/
|
|
865
|
-
set?: 'add' | 'update' | 'replace' | 'miss'
|
|
866
|
-
|
|
867
|
-
/**
|
|
868
|
-
* the ttl stored for the item, or undefined if ttls are not used.
|
|
869
|
-
*/
|
|
870
|
-
ttl?: LRUMilliseconds
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* the start time for the item, or undefined if ttls are not used.
|
|
874
|
-
*/
|
|
875
|
-
start?: LRUMilliseconds
|
|
876
|
-
|
|
877
|
-
/**
|
|
878
|
-
* The timestamp used for TTL calculation
|
|
879
|
-
*/
|
|
880
|
-
now?: LRUMilliseconds
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
* the remaining ttl for the item, or undefined if ttls are not used.
|
|
884
|
-
*/
|
|
885
|
-
remainingTTL?: LRUMilliseconds
|
|
886
|
-
|
|
887
|
-
/**
|
|
888
|
-
* The calculated size for the item, if sizes are used.
|
|
889
|
-
*/
|
|
890
|
-
size?: LRUSize
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* A flag indicating that the item was not stored, due to exceeding the
|
|
894
|
-
* {@link maxEntrySize}
|
|
895
|
-
*/
|
|
896
|
-
maxEntrySizeExceeded?: true
|
|
897
|
-
|
|
898
|
-
/**
|
|
899
|
-
* The old value, specified in the case of `set:'update'` or
|
|
900
|
-
* `set:'replace'`
|
|
901
|
-
*/
|
|
902
|
-
oldValue?: V
|
|
903
|
-
|
|
904
|
-
/**
|
|
905
|
-
* The results of a {@link has} operation
|
|
906
|
-
*
|
|
907
|
-
* - hit: the item was found in the cache
|
|
908
|
-
* - stale: the item was found in the cache, but is stale
|
|
909
|
-
* - miss: the item was not found in the cache
|
|
910
|
-
*/
|
|
911
|
-
has?: 'hit' | 'stale' | 'miss'
|
|
912
|
-
|
|
913
|
-
/**
|
|
914
|
-
* The status of a {@link fetch} operation.
|
|
915
|
-
* Note that this can change as the underlying fetch() moves through
|
|
916
|
-
* various states.
|
|
917
|
-
*
|
|
918
|
-
* - inflight: there is another fetch() for this key which is in process
|
|
919
|
-
* - get: there is no fetchMethod, so {@link get} was called.
|
|
920
|
-
* - miss: the item is not in cache, and will be fetched.
|
|
921
|
-
* - hit: the item is in the cache, and was resolved immediately.
|
|
922
|
-
* - stale: the item is in the cache, but stale.
|
|
923
|
-
* - refresh: the item is in the cache, and not stale, but
|
|
924
|
-
* {@link forceRefresh} was specified.
|
|
925
|
-
*/
|
|
926
|
-
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh'
|
|
927
|
-
|
|
928
|
-
/**
|
|
929
|
-
* The {@link fetchMethod} was called
|
|
930
|
-
*/
|
|
931
|
-
fetchDispatched?: true
|
|
932
|
-
|
|
933
|
-
/**
|
|
934
|
-
* The cached value was updated after a successful call to fetchMethod
|
|
935
|
-
*/
|
|
936
|
-
fetchUpdated?: true
|
|
937
|
-
|
|
938
|
-
/**
|
|
939
|
-
* The reason for a fetch() rejection. Either the error raised by the
|
|
940
|
-
* {@link fetchMethod}, or the reason for an AbortSignal.
|
|
941
|
-
*/
|
|
942
|
-
fetchError?: Error
|
|
943
|
-
|
|
944
|
-
/**
|
|
945
|
-
* The fetch received an abort signal
|
|
946
|
-
*/
|
|
947
|
-
fetchAborted?: true
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* The abort signal received was ignored, and the fetch was allowed to
|
|
951
|
-
* continue.
|
|
952
|
-
*/
|
|
953
|
-
fetchAbortIgnored?: true
|
|
954
|
-
|
|
955
|
-
/**
|
|
956
|
-
* The fetchMethod promise resolved successfully
|
|
957
|
-
*/
|
|
958
|
-
fetchResolved?: true
|
|
959
|
-
|
|
960
|
-
/**
|
|
961
|
-
* The results of the fetchMethod promise were stored in the cache
|
|
962
|
-
*/
|
|
963
|
-
fetchUpdated?: true
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* The fetchMethod promise was rejected
|
|
967
|
-
*/
|
|
968
|
-
fetchRejected?: true
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* The status of a {@link get} operation.
|
|
972
|
-
*
|
|
973
|
-
* - fetching: The item is currently being fetched. If a previous value is
|
|
974
|
-
* present and allowed, that will be returned.
|
|
975
|
-
* - stale: The item is in the cache, and is stale.
|
|
976
|
-
* - hit: the item is in the cache
|
|
977
|
-
* - miss: the item is not in the cache
|
|
978
|
-
*/
|
|
979
|
-
get?: 'stale' | 'hit' | 'miss'
|
|
980
|
-
|
|
981
|
-
/**
|
|
982
|
-
* A fetch or get operation returned a stale value.
|
|
983
|
-
*/
|
|
984
|
-
returnedStale?: true
|
|
985
|
-
}
|
|
986
|
-
```
|
|
105
|
+
For full description of the API and all options, please see [the
|
|
106
|
+
LRUCache typedocs](https://isaacs.github.io/node-lru-cache/)
|
|
987
107
|
|
|
988
108
|
## Storage Bounds Safety
|
|
989
109
|
|
|
@@ -1066,7 +186,7 @@ This cache never stores undefined values, as `undefined` is used
|
|
|
1066
186
|
internally in a few places to indicate that a key is not in the
|
|
1067
187
|
cache.
|
|
1068
188
|
|
|
1069
|
-
You may call `cache.set(key, undefined)`, but this is just
|
|
189
|
+
You may call `cache.set(key, undefined)`, but this is just
|
|
1070
190
|
an alias for `cache.delete(key)`. Note that this has the effect
|
|
1071
191
|
that `cache.has(key)` will return _false_ after setting it to
|
|
1072
192
|
undefined.
|
|
@@ -1195,10 +315,17 @@ before, it probably will not work in version 7 and above.
|
|
|
1195
315
|
- Minified export available at `'lru-cache/min'`, for both CJS
|
|
1196
316
|
and MJS builds.
|
|
1197
317
|
|
|
1198
|
-
## Changes in Version 9
|
|
318
|
+
## Breaking Changes in Version 9
|
|
1199
319
|
|
|
1200
320
|
- Named export only, no default export.
|
|
1201
321
|
- AbortController polyfill returned, albeit with a warning when
|
|
1202
322
|
used.
|
|
1203
323
|
|
|
324
|
+
## Breaking Changes in Version 10
|
|
325
|
+
|
|
326
|
+
- `cache.fetch()` return type is now `Promise<V | undefined>`
|
|
327
|
+
instead of `Promise<V | void>`. This is an irrelevant change
|
|
328
|
+
practically speaking, but can require changes for TypeScript
|
|
329
|
+
users.
|
|
330
|
+
|
|
1204
331
|
For more info, see the [change log](CHANGELOG.md).
|