From 818a2cff39f4d3e014b7c8ecc48cba158aa4e087 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 20 Apr 2022 15:22:45 -0700 Subject: [PATCH] deps: lru-cache@7.8.1 --- node_modules/lru-cache/index.js | 57 +++++++++++++++++++++-------- node_modules/lru-cache/package.json | 8 +++- package-lock.json | 18 ++++----- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/node_modules/lru-cache/index.js b/node_modules/lru-cache/index.js index 2168fd3a67bb4..b63be6e988835 100644 --- a/node_modules/lru-cache/index.js +++ b/node_modules/lru-cache/index.js @@ -3,7 +3,7 @@ const perf = typeof performance === 'object' && performance && const hasAbortController = typeof AbortController !== 'undefined' -/* istanbul ignore next - minimal backwards compatibility polyfill */ +// minimal backwards-compatibility polyfill const AC = hasAbortController ? AbortController : Object.assign( class AbortController { constructor () { this.signal = new AC.AbortSignal } @@ -36,14 +36,20 @@ const deprecatedProperty = (field, instead) => { } } -const shouldWarn = code => typeof process === 'object' && - process && - !warned.has(code) +const emitWarning = (...a) => { + typeof process === 'object' && + process && + typeof process.emitWarning === 'function' + ? process.emitWarning(...a) + : console.error(...a) +} + +const shouldWarn = code => !warned.has(code) const warn = (code, what, instead, fn) => { warned.add(code) const msg = `The ${what} is deprecated. Please use ${instead} instead.` - process.emitWarning(msg, 'DeprecationWarning', code, fn) + emitWarning(msg, 'DeprecationWarning', code, fn) } const isPosInt = n => n && n === Math.floor(n) && n > 0 && isFinite(n) @@ -72,7 +78,10 @@ class ZeroArray extends Array { class Stack { constructor (max) { - const UintArray = max ? getUintArray(max) : Array + if (max === 0) { + return [] + } + const UintArray = getUintArray(max) this.heap = new UintArray(max) this.length = 0 } @@ -92,6 +101,7 @@ class LRUCache { ttlResolution = 1, ttlAutopurge, updateAgeOnGet, + updateAgeOnHas, allowStale, dispose, disposeAfter, @@ -136,7 +146,6 @@ class LRUCache { throw new TypeError('fetchMethod must be a function if specified') } - this.keyMap = new Map() this.keyList = new Array(max).fill(null) this.valList = new Array(max).fill(null) @@ -170,6 +179,7 @@ class LRUCache { this.allowStale = !!allowStale || !!stale this.updateAgeOnGet = !!updateAgeOnGet + this.updateAgeOnHas = !!updateAgeOnHas this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1 this.ttlAutopurge = !!ttlAutopurge @@ -191,7 +201,7 @@ class LRUCache { warned.add(code) const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' + 'result in unbounded memory consumption.' - process.emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache) + emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache) } } @@ -207,7 +217,7 @@ class LRUCache { } getRemainingTTL (key) { - return this.has(key) ? Infinity : 0 + return this.has(key, { updateAgeOnHas: false }) ? Infinity : 0 } initializeTTLTracking () { @@ -292,7 +302,7 @@ class LRUCache { this.sizes[index] = size const maxSize = this.maxSize - this.sizes[index] while (this.calculatedSize > maxSize) { - this.evict() + this.evict(true) } this.calculatedSize += this.sizes[index] } @@ -512,8 +522,8 @@ class LRUCache { if (this.size === 0) { return this.tail } - if (this.size === this.max) { - return this.evict() + if (this.size === this.max && this.max !== 0) { + return this.evict(false) } if (this.free.length !== 0) { return this.free.pop() @@ -525,12 +535,12 @@ class LRUCache { pop () { if (this.size) { const val = this.valList[this.head] - this.evict() + this.evict(true) return val } } - evict () { + evict (free) { const head = this.head const k = this.keyList[head] const v = this.valList[head] @@ -543,14 +553,29 @@ class LRUCache { } } this.removeItemSize(head) + // if we aren't about to use the index, then null these out + if (free) { + this.keyList[head] = null + this.valList[head] = null + this.free.push(head) + } this.head = this.next[head] this.keyMap.delete(k) this.size -- return head } - has (k) { - return this.keyMap.has(k) && !this.isStale(this.keyMap.get(k)) + has (k, { updateAgeOnHas = this.updateAgeOnHas } = {}) { + const index = this.keyMap.get(k) + if (index !== undefined) { + if (!this.isStale(index)) { + if (updateAgeOnHas) { + this.updateItemAge(index) + } + return true + } + } + return false } // like get(), but without any LRU updating or TTL expiration diff --git a/node_modules/lru-cache/package.json b/node_modules/lru-cache/package.json index ca75abf004021..32fb9da24e56e 100644 --- a/node_modules/lru-cache/package.json +++ b/node_modules/lru-cache/package.json @@ -1,7 +1,7 @@ { "name": "lru-cache", "description": "A cache object that deletes the least-recently-used items.", - "version": "7.7.3", + "version": "7.8.1", "author": "Isaac Z. Schlueter ", "keywords": [ "mru", @@ -23,6 +23,7 @@ "@size-limit/preset-small-lib": "^7.0.8", "benchmark": "^2.1.4", "clock-mock": "^1.0.4", + "heapdump": "^0.3.15", "size-limit": "^7.0.8", "tap": "^15.1.6" }, @@ -34,7 +35,10 @@ "node": ">=12" }, "tap": { - "coverage-map": "map.js" + "coverage-map": "map.js", + "node-arg": [ + "--expose-gc" + ] }, "size-limit": [ { diff --git a/package-lock.json b/package-lock.json index b579791741e0b..bfec86b62493e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4564,9 +4564,9 @@ } }, "node_modules/lru-cache": { - "version": "7.7.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.7.3.tgz", - "integrity": "sha512-WY9wjJNQt9+PZilnLbuFKM+SwDull9+6IAguOrarOMoOHTcJ9GnXSO11+Gw6c7xtDkBkthR57OZMtZKYr+1CEw==", + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.8.1.tgz", + "integrity": "sha512-E1v547OCgJvbvevfjgK9sNKIVXO96NnsTsFPBlg4ZxjhsJSODoH9lk8Bm0OxvHNm6Vm5Yqkl/1fErDxhYL8Skg==", "inBundle": true, "engines": { "node": ">=12" @@ -10727,7 +10727,7 @@ "read-package-json-fast": "^2.0.2", "readdir-scoped-modules": "^1.1.0", "rimraf": "^3.0.2", - "semver": "7.3.7", + "semver": "^7.3.7", "ssri": "^9.0.0", "tap": "^16.0.1", "tcompare": "^5.0.6", @@ -13100,7 +13100,7 @@ "normalize-package-data": "^4.0.0", "npm-package-arg": "^9.0.1", "npm-registry-fetch": "^13.0.0", - "semver": "7.3.7", + "semver": "^7.3.7", "ssri": "^9.0.0", "tap": "^16.0.1" } @@ -13136,7 +13136,7 @@ "json-parse-even-better-errors": "^2.3.1", "proc-log": "^2.0.0", "require-inject": "^1.4.4", - "semver": "7.3.7", + "semver": "^7.3.7", "tap": "^16.0.1" } }, @@ -13224,9 +13224,9 @@ "peer": true }, "lru-cache": { - "version": "7.7.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.7.3.tgz", - "integrity": "sha512-WY9wjJNQt9+PZilnLbuFKM+SwDull9+6IAguOrarOMoOHTcJ9GnXSO11+Gw6c7xtDkBkthR57OZMtZKYr+1CEw==" + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.8.1.tgz", + "integrity": "sha512-E1v547OCgJvbvevfjgK9sNKIVXO96NnsTsFPBlg4ZxjhsJSODoH9lk8Bm0OxvHNm6Vm5Yqkl/1fErDxhYL8Skg==" }, "make-dir": { "version": "3.1.0",