diff options
author | Rebecca Turner <me@re-becca.org> | 2017-06-27 01:16:50 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2017-06-27 01:24:37 +0300 |
commit | 6f7a634cfd5cac28812af5c6fb4dc881b807e127 (patch) | |
tree | 74d21a1098c8dbcc9edac2346c29e1a44f5cbb7f /node_modules | |
parent | dbd9bffddf98af56924cff2f9130f26ff4c3e6d2 (diff) |
lru-cache@4.1.1
Diffstat (limited to 'node_modules')
-rw-r--r-- | node_modules/lru-cache/README.md | 4 | ||||
-rw-r--r-- | node_modules/lru-cache/index.js (renamed from node_modules/lru-cache/lib/lru-cache.js) | 182 | ||||
-rw-r--r-- | node_modules/lru-cache/package.json | 49 |
3 files changed, 119 insertions, 116 deletions
diff --git a/node_modules/lru-cache/README.md b/node_modules/lru-cache/README.md index 5bdf98c0f..f646c1cb8 100644 --- a/node_modules/lru-cache/README.md +++ b/node_modules/lru-cache/README.md @@ -66,6 +66,10 @@ away. `stale:true`, it'll return the stale value before deleting it. If you don't set this, then it'll return `undefined` when you try to get a stale entry, as if it had already been deleted. +* `noDisposeOnSet` By default, if you set a `dispose()` method, then + it'll be called whenever a `set()` operation overwrites an existing + key. If you set this option, `dispose()` will only be called when a + key falls out of the cache, not when it is overwritten. ## API diff --git a/node_modules/lru-cache/lib/lru-cache.js b/node_modules/lru-cache/index.js index e98ef78a5..460462aad 100644 --- a/node_modules/lru-cache/lib/lru-cache.js +++ b/node_modules/lru-cache/index.js @@ -1,3 +1,5 @@ +'use strict' + module.exports = LRUCache // This will be a proper iterable 'Map' in engines that support it, @@ -9,10 +11,8 @@ var util = require('util') var Yallist = require('yallist') // use symbols if possible, otherwise just _props -var symbols = {} var hasSymbol = typeof Symbol === 'function' var makeSymbol -/* istanbul ignore if */ if (hasSymbol) { makeSymbol = function (key) { return Symbol.for(key) @@ -23,21 +23,15 @@ if (hasSymbol) { } } -function priv (obj, key, val) { - var sym - if (symbols[key]) { - sym = symbols[key] - } else { - sym = makeSymbol(key) - symbols[key] = sym - } - if (arguments.length === 2) { - return obj[sym] - } else { - obj[sym] = val - return val - } -} +var MAX = makeSymbol('max') +var LENGTH = makeSymbol('length') +var LENGTH_CALCULATOR = makeSymbol('lengthCalculator') +var ALLOW_STALE = makeSymbol('allowStale') +var MAX_AGE = makeSymbol('maxAge') +var DISPOSE = makeSymbol('dispose') +var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet') +var LRU_LIST = makeSymbol('lruList') +var CACHE = makeSymbol('cache') function naiveLength () { return 1 } @@ -62,23 +56,24 @@ function LRUCache (options) { options = {} } - var max = priv(this, 'max', options.max) + var max = this[MAX] = options.max // Kind of weird to have a default max of Infinity, but oh well. if (!max || !(typeof max === 'number') || max <= 0) { - priv(this, 'max', Infinity) + this[MAX] = Infinity } var lc = options.length || naiveLength if (typeof lc !== 'function') { lc = naiveLength } - priv(this, 'lengthCalculator', lc) + this[LENGTH_CALCULATOR] = lc - priv(this, 'allowStale', options.stale || false) - priv(this, 'maxAge', options.maxAge || 0) - priv(this, 'dispose', options.dispose) + this[ALLOW_STALE] = options.stale || false + this[MAX_AGE] = options.maxAge || 0 + this[DISPOSE] = options.dispose + this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false this.reset() } @@ -88,21 +83,21 @@ Object.defineProperty(LRUCache.prototype, 'max', { if (!mL || !(typeof mL === 'number') || mL <= 0) { mL = Infinity } - priv(this, 'max', mL) + this[MAX] = mL trim(this) }, get: function () { - return priv(this, 'max') + return this[MAX] }, enumerable: true }) Object.defineProperty(LRUCache.prototype, 'allowStale', { set: function (allowStale) { - priv(this, 'allowStale', !!allowStale) + this[ALLOW_STALE] = !!allowStale }, get: function () { - return priv(this, 'allowStale') + return this[ALLOW_STALE] }, enumerable: true }) @@ -112,11 +107,11 @@ Object.defineProperty(LRUCache.prototype, 'maxAge', { if (!mA || !(typeof mA === 'number') || mA < 0) { mA = 0 } - priv(this, 'maxAge', mA) + this[MAX_AGE] = mA trim(this) }, get: function () { - return priv(this, 'maxAge') + return this[MAX_AGE] }, enumerable: true }) @@ -127,33 +122,33 @@ Object.defineProperty(LRUCache.prototype, 'lengthCalculator', { if (typeof lC !== 'function') { lC = naiveLength } - if (lC !== priv(this, 'lengthCalculator')) { - priv(this, 'lengthCalculator', lC) - priv(this, 'length', 0) - priv(this, 'lruList').forEach(function (hit) { - hit.length = priv(this, 'lengthCalculator').call(this, hit.value, hit.key) - priv(this, 'length', priv(this, 'length') + hit.length) + if (lC !== this[LENGTH_CALCULATOR]) { + this[LENGTH_CALCULATOR] = lC + this[LENGTH] = 0 + this[LRU_LIST].forEach(function (hit) { + hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key) + this[LENGTH] += hit.length }, this) } trim(this) }, - get: function () { return priv(this, 'lengthCalculator') }, + get: function () { return this[LENGTH_CALCULATOR] }, enumerable: true }) Object.defineProperty(LRUCache.prototype, 'length', { - get: function () { return priv(this, 'length') }, + get: function () { return this[LENGTH] }, enumerable: true }) Object.defineProperty(LRUCache.prototype, 'itemCount', { - get: function () { return priv(this, 'lruList').length }, + get: function () { return this[LRU_LIST].length }, enumerable: true }) LRUCache.prototype.rforEach = function (fn, thisp) { thisp = thisp || this - for (var walker = priv(this, 'lruList').tail; walker !== null;) { + for (var walker = this[LRU_LIST].tail; walker !== null;) { var prev = walker.prev forEachStep(this, fn, walker, thisp) walker = prev @@ -164,7 +159,7 @@ function forEachStep (self, fn, node, thisp) { var hit = node.value if (isStale(self, hit)) { del(self, node) - if (!priv(self, 'allowStale')) { + if (!self[ALLOW_STALE]) { hit = undefined } } @@ -175,7 +170,7 @@ function forEachStep (self, fn, node, thisp) { LRUCache.prototype.forEach = function (fn, thisp) { thisp = thisp || this - for (var walker = priv(this, 'lruList').head; walker !== null;) { + for (var walker = this[LRU_LIST].head; walker !== null;) { var next = walker.next forEachStep(this, fn, walker, thisp) walker = next @@ -183,33 +178,33 @@ LRUCache.prototype.forEach = function (fn, thisp) { } LRUCache.prototype.keys = function () { - return priv(this, 'lruList').toArray().map(function (k) { + return this[LRU_LIST].toArray().map(function (k) { return k.key }, this) } LRUCache.prototype.values = function () { - return priv(this, 'lruList').toArray().map(function (k) { + return this[LRU_LIST].toArray().map(function (k) { return k.value }, this) } LRUCache.prototype.reset = function () { - if (priv(this, 'dispose') && - priv(this, 'lruList') && - priv(this, 'lruList').length) { - priv(this, 'lruList').forEach(function (hit) { - priv(this, 'dispose').call(this, hit.key, hit.value) + if (this[DISPOSE] && + this[LRU_LIST] && + this[LRU_LIST].length) { + this[LRU_LIST].forEach(function (hit) { + this[DISPOSE](hit.key, hit.value) }, this) } - priv(this, 'cache', new Map()) // hash of items by key - priv(this, 'lruList', new Yallist()) // list of items in order of use recency - priv(this, 'length', 0) // length of items in the list + this[CACHE] = new Map() // hash of items by key + this[LRU_LIST] = new Yallist() // list of items in order of use recency + this[LENGTH] = 0 // length of items in the list } LRUCache.prototype.dump = function () { - return priv(this, 'lruList').map(function (hit) { + return this[LRU_LIST].map(function (hit) { if (!isStale(this, hit)) { return { k: hit.key, @@ -223,20 +218,20 @@ LRUCache.prototype.dump = function () { } LRUCache.prototype.dumpLru = function () { - return priv(this, 'lruList') + return this[LRU_LIST] } LRUCache.prototype.inspect = function (n, opts) { var str = 'LRUCache {' var extras = false - var as = priv(this, 'allowStale') + var as = this[ALLOW_STALE] if (as) { str += '\n allowStale: true' extras = true } - var max = priv(this, 'max') + var max = this[MAX] if (max && max !== Infinity) { if (extras) { str += ',' @@ -245,7 +240,7 @@ LRUCache.prototype.inspect = function (n, opts) { extras = true } - var maxAge = priv(this, 'maxAge') + var maxAge = this[MAX_AGE] if (maxAge) { if (extras) { str += ',' @@ -254,17 +249,17 @@ LRUCache.prototype.inspect = function (n, opts) { extras = true } - var lc = priv(this, 'lengthCalculator') + var lc = this[LENGTH_CALCULATOR] if (lc && lc !== naiveLength) { if (extras) { str += ',' } - str += '\n length: ' + util.inspect(priv(this, 'length'), opts) + str += '\n length: ' + util.inspect(this[LENGTH], opts) extras = true } var didFirst = false - priv(this, 'lruList').forEach(function (item) { + this[LRU_LIST].forEach(function (item) { if (didFirst) { str += ',\n ' } else { @@ -299,29 +294,32 @@ LRUCache.prototype.inspect = function (n, opts) { } LRUCache.prototype.set = function (key, value, maxAge) { - maxAge = maxAge || priv(this, 'maxAge') + maxAge = maxAge || this[MAX_AGE] var now = maxAge ? Date.now() : 0 - var len = priv(this, 'lengthCalculator').call(this, value, key) + var len = this[LENGTH_CALCULATOR](value, key) - if (priv(this, 'cache').has(key)) { - if (len > priv(this, 'max')) { - del(this, priv(this, 'cache').get(key)) + if (this[CACHE].has(key)) { + if (len > this[MAX]) { + del(this, this[CACHE].get(key)) return false } - var node = priv(this, 'cache').get(key) + var node = this[CACHE].get(key) var item = node.value // dispose of the old one before overwriting - if (priv(this, 'dispose')) { - priv(this, 'dispose').call(this, key, item.value) + // split out into 2 ifs for better coverage tracking + if (this[DISPOSE]) { + if (!this[NO_DISPOSE_ON_SET]) { + this[DISPOSE](key, item.value) + } } item.now = now item.maxAge = maxAge item.value = value - priv(this, 'length', priv(this, 'length') + (len - item.length)) + this[LENGTH] += len - item.length item.length = len this.get(key) trim(this) @@ -331,23 +329,23 @@ LRUCache.prototype.set = function (key, value, maxAge) { var hit = new Entry(key, value, len, now, maxAge) // oversized objects fall out of cache automatically. - if (hit.length > priv(this, 'max')) { - if (priv(this, 'dispose')) { - priv(this, 'dispose').call(this, key, value) + if (hit.length > this[MAX]) { + if (this[DISPOSE]) { + this[DISPOSE](key, value) } return false } - priv(this, 'length', priv(this, 'length') + hit.length) - priv(this, 'lruList').unshift(hit) - priv(this, 'cache').set(key, priv(this, 'lruList').head) + this[LENGTH] += hit.length + this[LRU_LIST].unshift(hit) + this[CACHE].set(key, this[LRU_LIST].head) trim(this) return true } LRUCache.prototype.has = function (key) { - if (!priv(this, 'cache').has(key)) return false - var hit = priv(this, 'cache').get(key).value + if (!this[CACHE].has(key)) return false + var hit = this[CACHE].get(key).value if (isStale(this, hit)) { return false } @@ -363,14 +361,14 @@ LRUCache.prototype.peek = function (key) { } LRUCache.prototype.pop = function () { - var node = priv(this, 'lruList').tail + var node = this[LRU_LIST].tail if (!node) return null del(this, node) return node.value } LRUCache.prototype.del = function (key) { - del(this, priv(this, 'cache').get(key)) + del(this, this[CACHE].get(key)) } LRUCache.prototype.load = function (arr) { @@ -397,21 +395,21 @@ LRUCache.prototype.load = function (arr) { LRUCache.prototype.prune = function () { var self = this - priv(this, 'cache').forEach(function (value, key) { + this[CACHE].forEach(function (value, key) { get(self, key, false) }) } function get (self, key, doUse) { - var node = priv(self, 'cache').get(key) + var node = self[CACHE].get(key) if (node) { var hit = node.value if (isStale(self, hit)) { del(self, node) - if (!priv(self, 'allowStale')) hit = undefined + if (!self[ALLOW_STALE]) hit = undefined } else { if (doUse) { - priv(self, 'lruList').unshiftNode(node) + self[LRU_LIST].unshiftNode(node) } } if (hit) hit = hit.value @@ -420,7 +418,7 @@ function get (self, key, doUse) { } function isStale (self, hit) { - if (!hit || (!hit.maxAge && !priv(self, 'maxAge'))) { + if (!hit || (!hit.maxAge && !self[MAX_AGE])) { return false } var stale = false @@ -428,15 +426,15 @@ function isStale (self, hit) { if (hit.maxAge) { stale = diff > hit.maxAge } else { - stale = priv(self, 'maxAge') && (diff > priv(self, 'maxAge')) + stale = self[MAX_AGE] && (diff > self[MAX_AGE]) } return stale } function trim (self) { - if (priv(self, 'length') > priv(self, 'max')) { - for (var walker = priv(self, 'lruList').tail; - priv(self, 'length') > priv(self, 'max') && walker !== null;) { + if (self[LENGTH] > self[MAX]) { + for (var walker = self[LRU_LIST].tail; + self[LENGTH] > self[MAX] && walker !== null;) { // We know that we're about to delete this one, and also // what the next least recently used key will be, so just // go ahead and set it now. @@ -450,12 +448,12 @@ function trim (self) { function del (self, node) { if (node) { var hit = node.value - if (priv(self, 'dispose')) { - priv(self, 'dispose').call(this, hit.key, hit.value) + if (self[DISPOSE]) { + self[DISPOSE](hit.key, hit.value) } - priv(self, 'length', priv(self, 'length') - hit.length) - priv(self, 'cache').delete(hit.key) - priv(self, 'lruList').removeNode(node) + self[LENGTH] -= hit.length + self[CACHE].delete(hit.key) + self[LRU_LIST].removeNode(node) } } diff --git a/node_modules/lru-cache/package.json b/node_modules/lru-cache/package.json index 5b40a7fe5..b419b5aa7 100644 --- a/node_modules/lru-cache/package.json +++ b/node_modules/lru-cache/package.json @@ -1,53 +1,53 @@ { - "_from": "lru-cache@~4.0.2", - "_id": "lru-cache@4.0.2", - "_integrity": "sha1-HRdnnAac2l0ECZGgnbwsDbN35V4=", + "_from": "lru-cache@4.1.1", + "_id": "lru-cache@4.1.1", + "_inBundle": false, + "_integrity": "sha512-q4spe4KTfsAS1SUHLO0wz8Qiyf1+vMIAgpRYioFYDMNqKfHQbg+AVDH3i4fvpl71/P1L0dBl+fQi+P37UYf0ew==", "_location": "/lru-cache", "_phantomChildren": {}, "_requested": { - "type": "range", + "type": "version", "registry": true, - "raw": "lru-cache@~4.0.2", + "raw": "lru-cache@4.1.1", "name": "lru-cache", "escapedName": "lru-cache", - "rawSpec": "~4.0.2", + "rawSpec": "4.1.1", "saveSpec": null, - "fetchSpec": "~4.0.2" + "fetchSpec": "4.1.1" }, "_requiredBy": [ + "#USER", "/", - "/cacache", "/pacote", "/pacote/make-fetch-happen", "/tap/foreground-child/cross-spawn", "/update-notifier/boxen/term-size/execa/cross-spawn-async" ], - "_resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.0.2.tgz", - "_shasum": "1d17679c069cda5d040991a09dbc2c0db377e55e", - "_shrinkwrap": null, - "_spec": "lru-cache@~4.0.2", - "_where": "/Users/zkat/Documents/code/npm", + "_resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz", + "_shasum": "622e32e82488b49279114a4f9ecf45e7cd6bba55", + "_spec": "lru-cache@4.1.1", + "_where": "/Users/rebecca/code/npm", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me" }, - "bin": null, "bugs": { "url": "https://github.com/isaacs/node-lru-cache/issues" }, "bundleDependencies": false, "dependencies": { - "pseudomap": "^1.0.1", - "yallist": "^2.0.0" + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" }, "deprecated": false, "description": "A cache object that deletes the least-recently-used items.", "devDependencies": { + "benchmark": "^2.1.4", "standard": "^5.4.1", - "tap": "^8.0.1" + "tap": "^10.3.3" }, "files": [ - "lib/lru-cache.js" + "index.js" ], "homepage": "https://github.com/isaacs/node-lru-cache#readme", "keywords": [ @@ -56,17 +56,18 @@ "cache" ], "license": "ISC", - "main": "lib/lru-cache.js", + "main": "index.js", "name": "lru-cache", - "optionalDependencies": {}, - "peerDependencies": {}, "repository": { "type": "git", "url": "git://github.com/isaacs/node-lru-cache.git" }, "scripts": { - "posttest": "standard test/*.js lib/*.js", - "test": "tap test --100" + "postpublish": "git push origin --all; git push origin --tags", + "posttest": "standard test/*.js index.js", + "postversion": "npm publish", + "preversion": "npm test", + "test": "tap test/*.js --100 -J" }, - "version": "4.0.2" + "version": "4.1.1" } |