Skip to content

Commit

Permalink
deps: lru-cache@7.13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Aug 10, 2022
1 parent a9b5306 commit 786f753
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
7 changes: 3 additions & 4 deletions node_modules/lru-cache/index.d.ts
@@ -1,4 +1,3 @@
// Type definitions for lru-cache 7.10.0
// Project: https://github.com/isaacs/node-lru-cache
// Based initially on @types/lru-cache
// https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down Expand Up @@ -32,7 +31,6 @@
// Changes by Isaac Z. Schlueter released under the terms found in the
// LICENSE file within this project.

/// <reference lib="DOM" />
//tslint:disable:member-access
declare class LRUCache<K, V> implements Iterable<[K, V]> {
constructor(options: LRUCache.Options<K, V>)
Expand Down Expand Up @@ -569,10 +567,11 @@ declare namespace LRUCache {
/**
* options which override the options set in the LRUCache constructor
* when making `cache.fetch()` calls.
* This is the union of GetOptions and SetOptions, plus the
* `noDeleteOnFetchRejection` and `fetchContext` fields.
* This is the union of GetOptions and SetOptions, plus
* `noDeleteOnFetchRejection`, `forceRefresh`, and `fetchContext`
*/
interface FetchOptions<K, V> extends FetcherFetchOptions<K, V> {
forceRefresh?: boolean
fetchContext?: any
}

Expand Down
39 changes: 28 additions & 11 deletions node_modules/lru-cache/index.js
Expand Up @@ -364,8 +364,10 @@ class LRUCache {
initializeSizeTracking() {
this.calculatedSize = 0
this.sizes = new ZeroArray(this.max)
this.removeItemSize = index =>
(this.calculatedSize -= this.sizes[index])
this.removeItemSize = index => {
this.calculatedSize -= this.sizes[index]
this.sizes[index] = 0
}
this.requireSize = (k, v, size, sizeCalculation) => {
if (!isPosInt(size)) {
if (sizeCalculation) {
Expand All @@ -386,7 +388,7 @@ class LRUCache {
}
return size
}
this.addItemSize = (index, v, k, size) => {
this.addItemSize = (index, size) => {
this.sizes[index] = size
const maxSize = this.maxSize - this.sizes[index]
while (this.calculatedSize > maxSize) {
Expand All @@ -396,7 +398,7 @@ class LRUCache {
}
}
removeItemSize(index) {}
addItemSize(index, v, k, size) {}
addItemSize(index, size) {}
requireSize(k, v, size, sizeCalculation) {
if (size || sizeCalculation) {
throw new TypeError(
Expand Down Expand Up @@ -523,7 +525,9 @@ class LRUCache {
for (const i of this.indexes({ allowStale: true })) {
const key = this.keyList[i]
const v = this.valList[i]
const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v
const value = this.isBackgroundFetch(v)
? v.__staleWhileFetching
: v
const entry = { value }
if (this.ttls) {
entry.ttl = this.ttls[i]
Expand Down Expand Up @@ -569,6 +573,10 @@ class LRUCache {
} = {}
) {
size = this.requireSize(k, v, size, sizeCalculation)
// if the item doesn't fit, don't do anything
if (this.maxSize && size > this.maxSize) {
return this
}
let index = this.size === 0 ? undefined : this.keyMap.get(k)
if (index === undefined) {
// addition
Expand All @@ -580,7 +588,7 @@ class LRUCache {
this.prev[index] = this.tail
this.tail = index
this.size++
this.addItemSize(index, v, k, size)
this.addItemSize(index, size)
noUpdateTTL = false
} else {
// update
Expand All @@ -598,7 +606,7 @@ class LRUCache {
}
this.removeItemSize(index)
this.valList[index] = v
this.addItemSize(index, v, k, size)
this.addItemSize(index, size)
}
this.moveToTail(index)
}
Expand Down Expand Up @@ -680,7 +688,9 @@ class LRUCache {
peek(k, { allowStale = this.allowStale } = {}) {
const index = this.keyMap.get(k)
if (index !== undefined && (allowStale || !this.isStale(index))) {
return this.valList[index]
const v = this.valList[index]
// either stale and allowed, or forcing a refresh of non-stale value
return this.isBackgroundFetch(v) ? v.__staleWhileFetching : v
}
}

Expand Down Expand Up @@ -763,10 +773,15 @@ class LRUCache {
// fetch exclusive options
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
fetchContext = this.fetchContext,
forceRefresh = false,
} = {}
) {
if (!this.fetchMethod) {
return this.get(k, { allowStale, updateAgeOnGet, noDeleteOnStaleGet })
return this.get(k, {
allowStale,
updateAgeOnGet,
noDeleteOnStaleGet,
})
}

const options = {
Expand Down Expand Up @@ -794,15 +809,17 @@ class LRUCache {
: (v.__returned = v)
}

if (!this.isStale(index)) {
// if we force a refresh, that means do NOT serve the cached value,
// unless we are already in the process of refreshing the cache.
if (!forceRefresh && !this.isStale(index)) {
this.moveToTail(index)
if (updateAgeOnGet) {
this.updateItemAge(index)
}
return v
}

// ok, it is stale, and not already fetching
// ok, it is stale or a forced refresh, and not already fetching.
// refresh the cache.
const p = this.backgroundFetch(k, index, options, fetchContext)
return allowStale && p.__staleWhileFetching !== undefined
Expand Down
5 changes: 3 additions & 2 deletions node_modules/lru-cache/package.json
@@ -1,13 +1,14 @@
{
"name": "lru-cache",
"description": "A cache object that deletes the least-recently-used items.",
"version": "7.12.0",
"version": "7.13.2",
"author": "Isaac Z. Schlueter <i@izs.me>",
"keywords": [
"mru",
"lru",
"cache"
],
"sideEffects": false,
"scripts": {
"build": "",
"size": "size-limit",
Expand All @@ -26,7 +27,7 @@
"@types/tap": "^15.0.6",
"benchmark": "^2.1.4",
"c8": "^7.11.2",
"clock-mock": "^1.0.4",
"clock-mock": "^1.0.6",
"eslint-config-prettier": "^8.5.0",
"prettier": "^2.6.2",
"size-limit": "^7.0.8",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json
Expand Up @@ -4598,9 +4598,9 @@
}
},
"node_modules/lru-cache": {
"version": "7.12.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.12.0.tgz",
"integrity": "sha512-OIP3DwzRZDfLg9B9VP/huWBlpvbkmbfiBy8xmsXp4RPmE4A3MhwNozc5ZJ3fWnSg8fDcdlE/neRTPG2ycEKliw==",
"version": "7.13.2",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.13.2.tgz",
"integrity": "sha512-VJL3nIpA79TodY/ctmZEfhASgqekbT574/c4j3jn4bKXbSCnTTCH/KltZyvL2GlV+tGSMtsWyem8DCX7qKTMBA==",
"inBundle": true,
"engines": {
"node": ">=12"
Expand Down

0 comments on commit 786f753

Please sign in to comment.