Skip to content

Commit 13299ee

Browse files
lukekarrysruyadorno
authored andcommitted
1 parent c51e553 commit 13299ee

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

node_modules/lru-cache/index.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const perf = typeof performance === 'object' && performance &&
33

44
const hasAbortController = typeof AbortController !== 'undefined'
55

6-
/* istanbul ignore next - minimal backwards compatibility polyfill */
6+
// minimal backwards-compatibility polyfill
77
const AC = hasAbortController ? AbortController : Object.assign(
88
class AbortController {
99
constructor () { this.signal = new AC.AbortSignal }
@@ -36,14 +36,20 @@ const deprecatedProperty = (field, instead) => {
3636
}
3737
}
3838

39-
const shouldWarn = code => typeof process === 'object' &&
40-
process &&
41-
!warned.has(code)
39+
const emitWarning = (...a) => {
40+
typeof process === 'object' &&
41+
process &&
42+
typeof process.emitWarning === 'function'
43+
? process.emitWarning(...a)
44+
: console.error(...a)
45+
}
46+
47+
const shouldWarn = code => !warned.has(code)
4248

4349
const warn = (code, what, instead, fn) => {
4450
warned.add(code)
4551
const msg = `The ${what} is deprecated. Please use ${instead} instead.`
46-
process.emitWarning(msg, 'DeprecationWarning', code, fn)
52+
emitWarning(msg, 'DeprecationWarning', code, fn)
4753
}
4854

4955
const isPosInt = n => n && n === Math.floor(n) && n > 0 && isFinite(n)
@@ -72,7 +78,10 @@ class ZeroArray extends Array {
7278

7379
class Stack {
7480
constructor (max) {
75-
const UintArray = max ? getUintArray(max) : Array
81+
if (max === 0) {
82+
return []
83+
}
84+
const UintArray = getUintArray(max)
7685
this.heap = new UintArray(max)
7786
this.length = 0
7887
}
@@ -92,6 +101,7 @@ class LRUCache {
92101
ttlResolution = 1,
93102
ttlAutopurge,
94103
updateAgeOnGet,
104+
updateAgeOnHas,
95105
allowStale,
96106
dispose,
97107
disposeAfter,
@@ -136,7 +146,6 @@ class LRUCache {
136146
throw new TypeError('fetchMethod must be a function if specified')
137147
}
138148

139-
140149
this.keyMap = new Map()
141150
this.keyList = new Array(max).fill(null)
142151
this.valList = new Array(max).fill(null)
@@ -170,6 +179,7 @@ class LRUCache {
170179

171180
this.allowStale = !!allowStale || !!stale
172181
this.updateAgeOnGet = !!updateAgeOnGet
182+
this.updateAgeOnHas = !!updateAgeOnHas
173183
this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0
174184
? ttlResolution : 1
175185
this.ttlAutopurge = !!ttlAutopurge
@@ -191,7 +201,7 @@ class LRUCache {
191201
warned.add(code)
192202
const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
193203
'result in unbounded memory consumption.'
194-
process.emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache)
204+
emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache)
195205
}
196206
}
197207

@@ -207,7 +217,7 @@ class LRUCache {
207217
}
208218

209219
getRemainingTTL (key) {
210-
return this.has(key) ? Infinity : 0
220+
return this.has(key, { updateAgeOnHas: false }) ? Infinity : 0
211221
}
212222

213223
initializeTTLTracking () {
@@ -292,7 +302,7 @@ class LRUCache {
292302
this.sizes[index] = size
293303
const maxSize = this.maxSize - this.sizes[index]
294304
while (this.calculatedSize > maxSize) {
295-
this.evict()
305+
this.evict(true)
296306
}
297307
this.calculatedSize += this.sizes[index]
298308
}
@@ -512,8 +522,8 @@ class LRUCache {
512522
if (this.size === 0) {
513523
return this.tail
514524
}
515-
if (this.size === this.max) {
516-
return this.evict()
525+
if (this.size === this.max && this.max !== 0) {
526+
return this.evict(false)
517527
}
518528
if (this.free.length !== 0) {
519529
return this.free.pop()
@@ -525,12 +535,12 @@ class LRUCache {
525535
pop () {
526536
if (this.size) {
527537
const val = this.valList[this.head]
528-
this.evict()
538+
this.evict(true)
529539
return val
530540
}
531541
}
532542

533-
evict () {
543+
evict (free) {
534544
const head = this.head
535545
const k = this.keyList[head]
536546
const v = this.valList[head]
@@ -543,14 +553,29 @@ class LRUCache {
543553
}
544554
}
545555
this.removeItemSize(head)
556+
// if we aren't about to use the index, then null these out
557+
if (free) {
558+
this.keyList[head] = null
559+
this.valList[head] = null
560+
this.free.push(head)
561+
}
546562
this.head = this.next[head]
547563
this.keyMap.delete(k)
548564
this.size --
549565
return head
550566
}
551567

552-
has (k) {
553-
return this.keyMap.has(k) && !this.isStale(this.keyMap.get(k))
568+
has (k, { updateAgeOnHas = this.updateAgeOnHas } = {}) {
569+
const index = this.keyMap.get(k)
570+
if (index !== undefined) {
571+
if (!this.isStale(index)) {
572+
if (updateAgeOnHas) {
573+
this.updateItemAge(index)
574+
}
575+
return true
576+
}
577+
}
578+
return false
554579
}
555580

556581
// like get(), but without any LRU updating or TTL expiration

node_modules/lru-cache/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "lru-cache",
33
"description": "A cache object that deletes the least-recently-used items.",
4-
"version": "7.7.3",
4+
"version": "7.8.1",
55
"author": "Isaac Z. Schlueter <[email protected]>",
66
"keywords": [
77
"mru",
@@ -23,6 +23,7 @@
2323
"@size-limit/preset-small-lib": "^7.0.8",
2424
"benchmark": "^2.1.4",
2525
"clock-mock": "^1.0.4",
26+
"heapdump": "^0.3.15",
2627
"size-limit": "^7.0.8",
2728
"tap": "^15.1.6"
2829
},
@@ -34,7 +35,10 @@
3435
"node": ">=12"
3536
},
3637
"tap": {
37-
"coverage-map": "map.js"
38+
"coverage-map": "map.js",
39+
"node-arg": [
40+
"--expose-gc"
41+
]
3842
},
3943
"size-limit": [
4044
{

package-lock.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,9 +4585,9 @@
45854585
}
45864586
},
45874587
"node_modules/lru-cache": {
4588-
"version": "7.7.3",
4589-
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.7.3.tgz",
4590-
"integrity": "sha512-WY9wjJNQt9+PZilnLbuFKM+SwDull9+6IAguOrarOMoOHTcJ9GnXSO11+Gw6c7xtDkBkthR57OZMtZKYr+1CEw==",
4588+
"version": "7.8.1",
4589+
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.8.1.tgz",
4590+
"integrity": "sha512-E1v547OCgJvbvevfjgK9sNKIVXO96NnsTsFPBlg4ZxjhsJSODoH9lk8Bm0OxvHNm6Vm5Yqkl/1fErDxhYL8Skg==",
45914591
"inBundle": true,
45924592
"engines": {
45934593
"node": ">=12"
@@ -10748,7 +10748,7 @@
1074810748
"read-package-json-fast": "^2.0.2",
1074910749
"readdir-scoped-modules": "^1.1.0",
1075010750
"rimraf": "^3.0.2",
10751-
"semver": "7.3.7",
10751+
"semver": "^7.3.7",
1075210752
"ssri": "^9.0.0",
1075310753
"tap": "^16.0.1",
1075410754
"tcompare": "^5.0.6",
@@ -13136,7 +13136,7 @@
1313613136
"normalize-package-data": "^4.0.0",
1313713137
"npm-package-arg": "^9.0.1",
1313813138
"npm-registry-fetch": "^13.0.0",
13139-
"semver": "7.3.7",
13139+
"semver": "^7.3.7",
1314013140
"ssri": "^9.0.0",
1314113141
"tap": "^16.0.1"
1314213142
}
@@ -13172,7 +13172,7 @@
1317213172
"json-parse-even-better-errors": "^2.3.1",
1317313173
"proc-log": "^2.0.0",
1317413174
"require-inject": "^1.4.4",
13175-
"semver": "7.3.7",
13175+
"semver": "^7.3.7",
1317613176
"tap": "^16.0.1"
1317713177
}
1317813178
},
@@ -13260,9 +13260,9 @@
1326013260
"peer": true
1326113261
},
1326213262
"lru-cache": {
13263-
"version": "7.7.3",
13264-
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.7.3.tgz",
13265-
"integrity": "sha512-WY9wjJNQt9+PZilnLbuFKM+SwDull9+6IAguOrarOMoOHTcJ9GnXSO11+Gw6c7xtDkBkthR57OZMtZKYr+1CEw=="
13263+
"version": "7.8.1",
13264+
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.8.1.tgz",
13265+
"integrity": "sha512-E1v547OCgJvbvevfjgK9sNKIVXO96NnsTsFPBlg4ZxjhsJSODoH9lk8Bm0OxvHNm6Vm5Yqkl/1fErDxhYL8Skg=="
1326613266
},
1326713267
"make-dir": {
1326813268
"version": "3.1.0",

0 commit comments

Comments
 (0)