Skip to content

Commit

Permalink
deps: lru-cache@7.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored and ruyadorno committed Apr 26, 2022
1 parent c51e553 commit 13299ee
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
57 changes: 41 additions & 16 deletions node_modules/lru-cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -92,6 +101,7 @@ class LRUCache {
ttlResolution = 1,
ttlAutopurge,
updateAgeOnGet,
updateAgeOnHas,
allowStale,
dispose,
disposeAfter,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}

Expand All @@ -207,7 +217,7 @@ class LRUCache {
}

getRemainingTTL (key) {
return this.has(key) ? Infinity : 0
return this.has(key, { updateAgeOnHas: false }) ? Infinity : 0
}

initializeTTLTracking () {
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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()
Expand All @@ -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]
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions node_modules/lru-cache/package.json
Original file line number Diff line number Diff line change
@@ -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 <i@izs.me>",
"keywords": [
"mru",
Expand All @@ -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"
},
Expand All @@ -34,7 +35,10 @@
"node": ">=12"
},
"tap": {
"coverage-map": "map.js"
"coverage-map": "map.js",
"node-arg": [
"--expose-gc"
]
},
"size-limit": [
{
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4585,9 +4585,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"
Expand Down Expand Up @@ -10748,7 +10748,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",
Expand Down Expand Up @@ -13136,7 +13136,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"
}
Expand Down Expand Up @@ -13172,7 +13172,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"
}
},
Expand Down Expand Up @@ -13260,9 +13260,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",
Expand Down

0 comments on commit 13299ee

Please sign in to comment.