fsevents 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fsevents might be problematic. Click here for more details.
- package/node_modules/ansi-styles/index.js +72 -6
- package/node_modules/ansi-styles/package.json +19 -12
- package/node_modules/ansi-styles/readme.md +36 -8
- package/node_modules/are-we-there-yet/CHANGES.md +19 -0
- package/node_modules/are-we-there-yet/README.md +12 -2
- package/node_modules/are-we-there-yet/index.js +4 -132
- package/node_modules/are-we-there-yet/package.json +18 -13
- package/node_modules/are-we-there-yet/test/lib/test-event.js +29 -0
- package/node_modules/are-we-there-yet/test/tracker.js +44 -43
- package/node_modules/are-we-there-yet/test/trackergroup.js +73 -64
- package/node_modules/are-we-there-yet/test/trackerstream.js +26 -40
- package/node_modules/are-we-there-yet/tracker-base.js +11 -0
- package/node_modules/are-we-there-yet/tracker-group.js +107 -0
- package/node_modules/are-we-there-yet/tracker-stream.js +35 -0
- package/node_modules/are-we-there-yet/tracker.js +30 -0
- package/node_modules/asn1/package.json +1 -2
- package/node_modules/assert-plus/package.json +1 -3
- package/node_modules/async/package.json +1 -1
- package/node_modules/aws4/.npmignore +2 -1
- package/node_modules/aws4/README.md +4 -0
- package/node_modules/aws4/aws4.js +8 -3
- package/node_modules/aws4/node_modules/lru-cache/.npmignore +3 -0
- package/node_modules/aws4/node_modules/lru-cache/.travis.yml +3 -4
- package/node_modules/aws4/node_modules/lru-cache/README.md +29 -24
- package/node_modules/aws4/node_modules/lru-cache/benchmarks/insertion-time.js +32 -0
- package/node_modules/aws4/node_modules/lru-cache/lib/lru-cache.js +333 -199
- package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/LICENSE +15 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/README.md +60 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/map.js +9 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/package.json +59 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/pseudomap.js +113 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/test/basic.js +86 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/.npmignore +4 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/.travis.yml +7 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/CONTRIBUTING.md +4 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/LICENSE +15 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/README.md +204 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/package.json +59 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/test/basic.js +188 -0
- package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/yallist.js +360 -0
- package/node_modules/aws4/node_modules/lru-cache/package.json +16 -12
- package/node_modules/aws4/node_modules/lru-cache/test/basic.js +270 -146
- package/node_modules/aws4/node_modules/lru-cache/test/foreach.js +39 -25
- package/node_modules/aws4/node_modules/lru-cache/test/inspect.js +54 -0
- package/node_modules/aws4/node_modules/lru-cache/test/no-symbol.js +3 -0
- package/node_modules/aws4/node_modules/lru-cache/test/serialize.js +115 -104
- package/node_modules/aws4/package.json +17 -14
- package/node_modules/bl/bl.js +9 -3
- package/node_modules/bl/package.json +12 -12
- package/node_modules/bl/test/test.js +14 -0
- package/node_modules/color-convert/README.md +62 -0
- package/node_modules/color-convert/conversions.js +594 -0
- package/node_modules/color-convert/css-keywords.js +151 -0
- package/node_modules/color-convert/index.js +75 -0
- package/node_modules/color-convert/package.json +92 -0
- package/node_modules/color-convert/route.js +98 -0
- package/node_modules/dashdash/lib/dashdash.js +1 -1
- package/node_modules/dashdash/node_modules/assert-plus/AUTHORS +6 -0
- package/node_modules/dashdash/node_modules/assert-plus/CHANGES.md +14 -0
- package/node_modules/dashdash/node_modules/assert-plus/README.md +162 -0
- package/node_modules/dashdash/node_modules/assert-plus/assert.js +211 -0
- package/node_modules/dashdash/node_modules/assert-plus/package.json +89 -0
- package/node_modules/dashdash/package.json +19 -12
- package/node_modules/ecc-jsbn/package.json +1 -2
- package/node_modules/escape-string-regexp/package.json +15 -11
- package/node_modules/extsprintf/package.json +2 -3
- package/node_modules/form-data/.dockerignore +7 -0
- package/node_modules/form-data/.editorconfig +10 -0
- package/node_modules/form-data/.eslintignore +1 -0
- package/node_modules/form-data/.eslintrc +64 -0
- package/node_modules/form-data/{Readme.md → README.md} +9 -1
- package/node_modules/form-data/lib/browser.js +2 -1
- package/node_modules/form-data/lib/form_data.js +172 -135
- package/node_modules/form-data/lib/populate.js +9 -0
- package/node_modules/form-data/package.json +35 -16
- package/node_modules/form-data/wercker.yml +36 -0
- package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/index.js +1 -1
- package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/package.json +14 -10
- package/node_modules/gauge/README.md +1 -1
- package/node_modules/gauge/package.json +18 -14
- package/node_modules/gauge/progress-bar.js +2 -2
- package/node_modules/http-signature/package.json +1 -2
- package/node_modules/is-my-json-valid/README.md +2 -2
- package/node_modules/is-my-json-valid/index.js +15 -6
- package/node_modules/is-my-json-valid/package.json +11 -7
- package/node_modules/is-my-json-valid/test/json-schema-draft4/multipleOf.json +36 -0
- package/node_modules/is-my-json-valid/test/misc.js +18 -0
- package/node_modules/is-typedarray/package.json +1 -2
- package/node_modules/isarray/.npmignore +1 -0
- package/node_modules/isarray/.travis.yml +4 -0
- package/node_modules/isarray/Makefile +6 -0
- package/node_modules/isarray/README.md +6 -0
- package/node_modules/isarray/index.js +3 -1
- package/node_modules/isarray/package.json +28 -10
- package/node_modules/isarray/test.js +20 -0
- package/node_modules/jodid25519/package.json +1 -2
- package/node_modules/jsbn/package.json +1 -2
- package/node_modules/json-schema/package.json +1 -1
- package/node_modules/jsprim/package.json +1 -2
- package/node_modules/lodash.pad/LICENSE +17 -16
- package/node_modules/lodash.pad/README.md +2 -2
- package/node_modules/lodash.pad/index.js +3 -94
- package/node_modules/lodash.pad/package.json +12 -12
- package/node_modules/lodash.padend/LICENSE +23 -0
- package/node_modules/lodash.padend/README.md +18 -0
- package/node_modules/lodash.padend/index.js +285 -0
- package/node_modules/lodash.padend/package.json +91 -0
- package/node_modules/lodash.padstart/LICENSE +23 -0
- package/node_modules/lodash.padstart/README.md +18 -0
- package/node_modules/lodash.padstart/index.js +285 -0
- package/node_modules/lodash.padstart/package.json +91 -0
- package/node_modules/lodash.repeat/LICENSE +17 -16
- package/node_modules/lodash.repeat/README.md +2 -2
- package/node_modules/lodash.repeat/index.js +3 -94
- package/node_modules/lodash.repeat/package.json +14 -13
- package/node_modules/lodash.tostring/LICENSE +23 -0
- package/node_modules/lodash.tostring/README.md +18 -0
- package/node_modules/lodash.tostring/index.js +164 -0
- package/node_modules/lodash.tostring/package.json +91 -0
- package/node_modules/mime-db/HISTORY.md +14 -0
- package/node_modules/mime-db/db.json +26 -3
- package/node_modules/mime-db/package.json +23 -18
- package/node_modules/mime-types/HISTORY.md +8 -0
- package/node_modules/mime-types/README.md +1 -1
- package/node_modules/mime-types/package.json +21 -16
- package/node_modules/node-pre-gyp/CHANGELOG.md +11 -0
- package/node_modules/node-pre-gyp/lib/util/abi_crosswalk.json +44 -4
- package/node_modules/node-pre-gyp/package.json +16 -16
- package/node_modules/npmlog/.nyc_output/64996.json +1 -0
- package/node_modules/npmlog/.nyc_output/64998.json +1 -0
- package/node_modules/npmlog/.nyc_output/65000.json +1 -0
- package/node_modules/npmlog/log.js +3 -2
- package/node_modules/npmlog/package.json +15 -11
- package/node_modules/npmlog/test/progress.js +25 -8
- package/node_modules/once/package.json +1 -1
- package/node_modules/qs/package.json +1 -2
- package/node_modules/readable-stream/.travis.yml +18 -16
- package/node_modules/readable-stream/README.md +1 -1
- package/node_modules/readable-stream/doc/stream.markdown +435 -405
- package/node_modules/readable-stream/lib/_stream_duplex.js +13 -20
- package/node_modules/readable-stream/lib/_stream_passthrough.js +3 -4
- package/node_modules/readable-stream/lib/_stream_readable.js +110 -205
- package/node_modules/readable-stream/lib/_stream_transform.js +21 -38
- package/node_modules/readable-stream/lib/_stream_writable.js +108 -121
- package/node_modules/readable-stream/package.json +19 -15
- package/node_modules/request/package.json +1 -2
- package/node_modules/rimraf/node_modules/glob/README.md +6 -0
- package/node_modules/rimraf/node_modules/glob/common.js +12 -3
- package/node_modules/rimraf/node_modules/glob/glob.js +20 -3
- package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/index.js +1 -1
- package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/package.json +14 -10
- package/node_modules/rimraf/node_modules/glob/package.json +15 -11
- package/node_modules/rimraf/node_modules/glob/sync.js +8 -1
- package/node_modules/rimraf/package.json +14 -10
- package/node_modules/semver/package.json +1 -2
- package/node_modules/sshpk/lib/formats/rfc4253.js +2 -1
- package/node_modules/sshpk/package.json +13 -10
- package/node_modules/strip-ansi/package.json +21 -16
- package/node_modules/strip-ansi/readme.md +5 -5
- package/node_modules/tough-cookie/lib/cookie.js +2 -2
- package/node_modules/tough-cookie/package.json +13 -9
- package/node_modules/tweetnacl/CHANGELOG.md +53 -0
- package/node_modules/tweetnacl/COPYING.txt +9 -0
- package/node_modules/tweetnacl/README.md +14 -40
- package/node_modules/tweetnacl/nacl-fast.js +21 -51
- package/node_modules/tweetnacl/nacl-fast.min.js +2 -2
- package/node_modules/tweetnacl/nacl.js +21 -51
- package/node_modules/tweetnacl/nacl.min.js +1 -1
- package/node_modules/tweetnacl/package.json +28 -38
- package/node_modules/verror/package.json +2 -3
- package/package.json +2 -2
- package/node_modules/aws4/example.js +0 -372
- package/node_modules/aws4/node_modules/lru-cache/test/memory-leak.js +0 -51
- package/node_modules/isarray/build/build.js +0 -209
- package/node_modules/lodash._basetostring/LICENSE +0 -22
- package/node_modules/lodash._basetostring/README.md +0 -20
- package/node_modules/lodash._basetostring/index.js +0 -22
- package/node_modules/lodash._basetostring/package.json +0 -99
- package/node_modules/lodash._createpadding/LICENSE +0 -22
- package/node_modules/lodash._createpadding/README.md +0 -20
- package/node_modules/lodash._createpadding/index.js +0 -37
- package/node_modules/lodash._createpadding/package.json +0 -101
- package/node_modules/lodash._root/LICENSE +0 -22
- package/node_modules/lodash._root/README.md +0 -18
- package/node_modules/lodash._root/index.js +0 -53
- package/node_modules/lodash._root/package.json +0 -77
- package/node_modules/lodash.padleft/LICENSE.txt +0 -22
- package/node_modules/lodash.padleft/README.md +0 -20
- package/node_modules/lodash.padleft/index.js +0 -50
- package/node_modules/lodash.padleft/package.json +0 -107
- package/node_modules/lodash.padright/LICENSE.txt +0 -22
- package/node_modules/lodash.padright/README.md +0 -20
- package/node_modules/lodash.padright/index.js +0 -50
- package/node_modules/lodash.padright/package.json +0 -107
@@ -1,225 +1,352 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module.exports = LRUCache
|
2
|
+
|
3
|
+
// This will be a proper iterable 'Map' in engines that support it,
|
4
|
+
// or a fakey-fake PseudoMap in older versions.
|
5
|
+
var Map = require('pseudomap')
|
6
|
+
var util = require('util')
|
7
|
+
|
8
|
+
// A linked list to keep track of recently-used-ness
|
9
|
+
var Yallist = require('yallist')
|
10
|
+
|
11
|
+
// use symbols if possible, otherwise just _props
|
12
|
+
var symbols = {}
|
13
|
+
var hasSymbol = typeof Symbol === 'function'
|
14
|
+
var makeSymbol
|
15
|
+
if (hasSymbol) {
|
16
|
+
makeSymbol = function (key) {
|
17
|
+
return Symbol.for(key)
|
18
|
+
}
|
5
19
|
} else {
|
6
|
-
|
7
|
-
|
20
|
+
makeSymbol = function (key) {
|
21
|
+
return '_' + key
|
22
|
+
}
|
8
23
|
}
|
9
24
|
|
10
|
-
function
|
11
|
-
|
25
|
+
function priv (obj, key, val) {
|
26
|
+
var sym
|
27
|
+
if (symbols[key]) {
|
28
|
+
sym = symbols[key]
|
29
|
+
} else {
|
30
|
+
sym = makeSymbol(key)
|
31
|
+
symbols[key] = sym
|
32
|
+
}
|
33
|
+
if (arguments.length === 2) {
|
34
|
+
return obj[sym]
|
35
|
+
} else {
|
36
|
+
obj[sym] = val
|
37
|
+
return val
|
38
|
+
}
|
12
39
|
}
|
13
40
|
|
14
41
|
function naiveLength () { return 1 }
|
15
42
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
43
|
+
// lruList is a yallist where the head is the youngest
|
44
|
+
// item, and the tail is the oldest. the list contains the Hit
|
45
|
+
// objects as the entries.
|
46
|
+
// Each Hit object has a reference to its Yallist.Node. This
|
47
|
+
// never changes.
|
48
|
+
//
|
49
|
+
// cache is a Map (or PseudoMap) that matches the keys to
|
50
|
+
// the Yallist.Node object.
|
24
51
|
function LRUCache (options) {
|
25
|
-
if (!(this instanceof LRUCache))
|
52
|
+
if (!(this instanceof LRUCache)) {
|
26
53
|
return new LRUCache(options)
|
54
|
+
}
|
27
55
|
|
28
|
-
if (typeof options === 'number')
|
56
|
+
if (typeof options === 'number') {
|
29
57
|
options = { max: options }
|
58
|
+
}
|
30
59
|
|
31
|
-
if (!options)
|
60
|
+
if (!options) {
|
32
61
|
options = {}
|
62
|
+
}
|
33
63
|
|
34
|
-
|
64
|
+
var max = priv(this, 'max', options.max)
|
35
65
|
// Kind of weird to have a default max of Infinity, but oh well.
|
36
|
-
if (!
|
37
|
-
|
66
|
+
if (!max ||
|
67
|
+
!(typeof max === 'number') ||
|
68
|
+
max <= 0) {
|
69
|
+
priv(this, 'max', Infinity)
|
70
|
+
}
|
38
71
|
|
39
|
-
|
40
|
-
if (typeof
|
41
|
-
|
72
|
+
var lc = options.length || naiveLength
|
73
|
+
if (typeof lc !== 'function') {
|
74
|
+
lc = naiveLength
|
75
|
+
}
|
76
|
+
priv(this, 'lengthCalculator', lc)
|
42
77
|
|
43
|
-
this
|
44
|
-
this
|
45
|
-
this
|
78
|
+
priv(this, 'allowStale', options.stale || false)
|
79
|
+
priv(this, 'maxAge', options.maxAge || 0)
|
80
|
+
priv(this, 'dispose', options.dispose)
|
46
81
|
this.reset()
|
47
82
|
}
|
48
83
|
|
49
84
|
// resize the cache when the max changes.
|
50
|
-
Object.defineProperty(LRUCache.prototype,
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
if (this._length > this._max) trim(this)
|
85
|
+
Object.defineProperty(LRUCache.prototype, 'max', {
|
86
|
+
set: function (mL) {
|
87
|
+
if (!mL || !(typeof mL === 'number') || mL <= 0) {
|
88
|
+
mL = Infinity
|
55
89
|
}
|
56
|
-
|
57
|
-
|
58
|
-
}
|
90
|
+
priv(this, 'max', mL)
|
91
|
+
trim(this)
|
92
|
+
},
|
93
|
+
get: function () {
|
94
|
+
return priv(this, 'max')
|
95
|
+
},
|
96
|
+
enumerable: true
|
97
|
+
})
|
98
|
+
|
99
|
+
Object.defineProperty(LRUCache.prototype, 'allowStale', {
|
100
|
+
set: function (allowStale) {
|
101
|
+
priv(this, 'allowStale', !!allowStale)
|
102
|
+
},
|
103
|
+
get: function () {
|
104
|
+
return priv(this, 'allowStale')
|
105
|
+
},
|
106
|
+
enumerable: true
|
107
|
+
})
|
108
|
+
|
109
|
+
Object.defineProperty(LRUCache.prototype, 'maxAge', {
|
110
|
+
set: function (mA) {
|
111
|
+
if (!mA || !(typeof mA === 'number') || mA < 0) {
|
112
|
+
mA = 0
|
113
|
+
}
|
114
|
+
priv(this, 'maxAge', mA)
|
115
|
+
trim(this)
|
116
|
+
},
|
117
|
+
get: function () {
|
118
|
+
return priv(this, 'maxAge')
|
119
|
+
},
|
120
|
+
enumerable: true
|
121
|
+
})
|
59
122
|
|
60
123
|
// resize the cache when the lengthCalculator changes.
|
61
|
-
Object.defineProperty(LRUCache.prototype,
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
this._length = this._itemCount
|
66
|
-
for (var key in this._cache) {
|
67
|
-
this._cache[key].length = 1
|
68
|
-
}
|
69
|
-
} else {
|
70
|
-
this._lengthCalculator = lC
|
71
|
-
this._length = 0
|
72
|
-
for (var key in this._cache) {
|
73
|
-
this._cache[key].length = this._lengthCalculator(this._cache[key].value)
|
74
|
-
this._length += this._cache[key].length
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
if (this._length > this._max) trim(this)
|
124
|
+
Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
|
125
|
+
set: function (lC) {
|
126
|
+
if (typeof lC !== 'function') {
|
127
|
+
lC = naiveLength
|
79
128
|
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
129
|
+
if (lC !== priv(this, 'lengthCalculator')) {
|
130
|
+
priv(this, 'lengthCalculator', lC)
|
131
|
+
priv(this, 'length', 0)
|
132
|
+
priv(this, 'lruList').forEach(function (hit) {
|
133
|
+
hit.length = priv(this, 'lengthCalculator').call(this, hit.value, hit.key)
|
134
|
+
priv(this, 'length', priv(this, 'length') + hit.length)
|
135
|
+
}, this)
|
136
|
+
}
|
137
|
+
trim(this)
|
138
|
+
},
|
139
|
+
get: function () { return priv(this, 'lengthCalculator') },
|
140
|
+
enumerable: true
|
141
|
+
})
|
142
|
+
|
143
|
+
Object.defineProperty(LRUCache.prototype, 'length', {
|
144
|
+
get: function () { return priv(this, 'length') },
|
145
|
+
enumerable: true
|
146
|
+
})
|
147
|
+
|
148
|
+
Object.defineProperty(LRUCache.prototype, 'itemCount', {
|
149
|
+
get: function () { return priv(this, 'lruList').length },
|
150
|
+
enumerable: true
|
151
|
+
})
|
152
|
+
|
153
|
+
LRUCache.prototype.rforEach = function (fn, thisp) {
|
154
|
+
thisp = thisp || this
|
155
|
+
for (var walker = priv(this, 'lruList').tail; walker !== null;) {
|
156
|
+
var prev = walker.prev
|
157
|
+
forEachStep(this, fn, walker, thisp)
|
158
|
+
walker = prev
|
159
|
+
}
|
160
|
+
}
|
89
161
|
|
90
|
-
|
91
|
-
|
92
|
-
,
|
93
|
-
|
162
|
+
function forEachStep (self, fn, node, thisp) {
|
163
|
+
var hit = node.value
|
164
|
+
if (isStale(self, hit)) {
|
165
|
+
del(self, node)
|
166
|
+
if (!priv(self, 'allowStale')) {
|
167
|
+
hit = undefined
|
168
|
+
}
|
169
|
+
}
|
170
|
+
if (hit) {
|
171
|
+
fn.call(thisp, hit.value, hit.key, self)
|
172
|
+
}
|
173
|
+
}
|
94
174
|
|
95
175
|
LRUCache.prototype.forEach = function (fn, thisp) {
|
96
176
|
thisp = thisp || this
|
97
|
-
var
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
i++
|
102
|
-
var hit = this._lruList[k]
|
103
|
-
if (isStale(this, hit)) {
|
104
|
-
del(this, hit)
|
105
|
-
if (!this._allowStale) hit = undefined
|
106
|
-
}
|
107
|
-
if (hit) {
|
108
|
-
fn.call(thisp, hit.value, hit.key, this)
|
109
|
-
}
|
177
|
+
for (var walker = priv(this, 'lruList').head; walker !== null;) {
|
178
|
+
var next = walker.next
|
179
|
+
forEachStep(this, fn, walker, thisp)
|
180
|
+
walker = next
|
110
181
|
}
|
111
182
|
}
|
112
183
|
|
113
184
|
LRUCache.prototype.keys = function () {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
var hit = this._lruList[k]
|
118
|
-
keys[i++] = hit.key
|
119
|
-
}
|
120
|
-
return keys
|
185
|
+
return priv(this, 'lruList').toArray().map(function (k) {
|
186
|
+
return k.key
|
187
|
+
}, this)
|
121
188
|
}
|
122
189
|
|
123
190
|
LRUCache.prototype.values = function () {
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
var hit = this._lruList[k]
|
128
|
-
values[i++] = hit.value
|
129
|
-
}
|
130
|
-
return values
|
191
|
+
return priv(this, 'lruList').toArray().map(function (k) {
|
192
|
+
return k.value
|
193
|
+
}, this)
|
131
194
|
}
|
132
195
|
|
133
196
|
LRUCache.prototype.reset = function () {
|
134
|
-
if (this
|
135
|
-
|
136
|
-
this
|
137
|
-
|
197
|
+
if (priv(this, 'dispose') &&
|
198
|
+
priv(this, 'lruList') &&
|
199
|
+
priv(this, 'lruList').length) {
|
200
|
+
priv(this, 'lruList').forEach(function (hit) {
|
201
|
+
priv(this, 'dispose').call(this, hit.key, hit.value)
|
202
|
+
}, this)
|
138
203
|
}
|
139
204
|
|
140
|
-
this
|
141
|
-
this
|
142
|
-
this
|
143
|
-
this._lru = 0 // least recently used
|
144
|
-
this._length = 0 // number of items in the list
|
145
|
-
this._itemCount = 0
|
205
|
+
priv(this, 'cache', new Map()) // hash of items by key
|
206
|
+
priv(this, 'lruList', new Yallist()) // list of items in order of use recency
|
207
|
+
priv(this, 'length', 0) // length of items in the list
|
146
208
|
}
|
147
209
|
|
148
210
|
LRUCache.prototype.dump = function () {
|
149
|
-
|
150
|
-
var i = 0
|
151
|
-
|
152
|
-
for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
|
153
|
-
var hit = this._lruList[k]
|
211
|
+
return priv(this, 'lruList').map(function (hit) {
|
154
212
|
if (!isStale(this, hit)) {
|
155
|
-
|
156
|
-
++i
|
157
|
-
arr.push({
|
213
|
+
return {
|
158
214
|
k: hit.key,
|
159
215
|
v: hit.value,
|
160
216
|
e: hit.now + (hit.maxAge || 0)
|
161
|
-
}
|
217
|
+
}
|
162
218
|
}
|
163
|
-
}
|
164
|
-
|
165
|
-
|
219
|
+
}, this).toArray().filter(function (h) {
|
220
|
+
return h
|
221
|
+
})
|
166
222
|
}
|
167
223
|
|
168
224
|
LRUCache.prototype.dumpLru = function () {
|
169
|
-
return this
|
225
|
+
return priv(this, 'lruList')
|
226
|
+
}
|
227
|
+
|
228
|
+
LRUCache.prototype.inspect = function (n, opts) {
|
229
|
+
var str = 'LRUCache {'
|
230
|
+
var extras = false
|
231
|
+
|
232
|
+
var as = priv(this, 'allowStale')
|
233
|
+
if (as) {
|
234
|
+
str += '\n allowStale: true'
|
235
|
+
extras = true
|
236
|
+
}
|
237
|
+
|
238
|
+
var max = priv(this, 'max')
|
239
|
+
if (max && max !== Infinity) {
|
240
|
+
if (extras) {
|
241
|
+
str += ','
|
242
|
+
}
|
243
|
+
str += '\n max: ' + util.inspect(max, opts)
|
244
|
+
extras = true
|
245
|
+
}
|
246
|
+
|
247
|
+
var maxAge = priv(this, 'maxAge')
|
248
|
+
if (maxAge) {
|
249
|
+
if (extras) {
|
250
|
+
str += ','
|
251
|
+
}
|
252
|
+
str += '\n maxAge: ' + util.inspect(maxAge, opts)
|
253
|
+
extras = true
|
254
|
+
}
|
255
|
+
|
256
|
+
var lc = priv(this, 'lengthCalculator')
|
257
|
+
if (lc && lc !== naiveLength) {
|
258
|
+
if (extras) {
|
259
|
+
str += ','
|
260
|
+
}
|
261
|
+
str += '\n length: ' + util.inspect(priv(this, 'length'), opts)
|
262
|
+
extras = true
|
263
|
+
}
|
264
|
+
|
265
|
+
var didFirst = false
|
266
|
+
priv(this, 'lruList').forEach(function (item) {
|
267
|
+
if (didFirst) {
|
268
|
+
str += ',\n '
|
269
|
+
} else {
|
270
|
+
if (extras) {
|
271
|
+
str += ',\n'
|
272
|
+
}
|
273
|
+
didFirst = true
|
274
|
+
str += '\n '
|
275
|
+
}
|
276
|
+
var key = util.inspect(item.key).split('\n').join('\n ')
|
277
|
+
var val = { value: item.value }
|
278
|
+
if (item.maxAge !== maxAge) {
|
279
|
+
val.maxAge = item.maxAge
|
280
|
+
}
|
281
|
+
if (lc !== naiveLength) {
|
282
|
+
val.length = item.length
|
283
|
+
}
|
284
|
+
if (isStale(this, item)) {
|
285
|
+
val.stale = true
|
286
|
+
}
|
287
|
+
|
288
|
+
val = util.inspect(val, opts).split('\n').join('\n ')
|
289
|
+
str += key + ' => ' + val
|
290
|
+
})
|
291
|
+
|
292
|
+
if (didFirst || extras) {
|
293
|
+
str += '\n'
|
294
|
+
}
|
295
|
+
str += '}'
|
296
|
+
|
297
|
+
return str
|
170
298
|
}
|
171
299
|
|
172
300
|
LRUCache.prototype.set = function (key, value, maxAge) {
|
173
|
-
maxAge = maxAge || this
|
174
|
-
typeCheckKey(key)
|
301
|
+
maxAge = maxAge || priv(this, 'maxAge')
|
175
302
|
|
176
303
|
var now = maxAge ? Date.now() : 0
|
177
|
-
var len = this.
|
304
|
+
var len = priv(this, 'lengthCalculator').call(this, value, key)
|
178
305
|
|
179
|
-
if (
|
180
|
-
if (len > this
|
181
|
-
del(this, this.
|
306
|
+
if (priv(this, 'cache').has(key)) {
|
307
|
+
if (len > priv(this, 'max')) {
|
308
|
+
del(this, priv(this, 'cache').get(key))
|
182
309
|
return false
|
183
310
|
}
|
184
|
-
// dispose of the old one before overwriting
|
185
|
-
if (this._dispose)
|
186
|
-
this._dispose(key, this._cache[key].value)
|
187
|
-
|
188
|
-
this._cache[key].now = now
|
189
|
-
this._cache[key].maxAge = maxAge
|
190
|
-
this._cache[key].value = value
|
191
|
-
this._length += (len - this._cache[key].length)
|
192
|
-
this._cache[key].length = len
|
193
|
-
this.get(key)
|
194
311
|
|
195
|
-
|
196
|
-
|
312
|
+
var node = priv(this, 'cache').get(key)
|
313
|
+
var item = node.value
|
314
|
+
|
315
|
+
// dispose of the old one before overwriting
|
316
|
+
if (priv(this, 'dispose')) {
|
317
|
+
priv(this, 'dispose').call(this, key, item.value)
|
318
|
+
}
|
197
319
|
|
320
|
+
item.now = now
|
321
|
+
item.maxAge = maxAge
|
322
|
+
item.value = value
|
323
|
+
priv(this, 'length', priv(this, 'length') + (len - item.length))
|
324
|
+
item.length = len
|
325
|
+
this.get(key)
|
326
|
+
trim(this)
|
198
327
|
return true
|
199
328
|
}
|
200
329
|
|
201
|
-
var hit = new Entry(key, value,
|
330
|
+
var hit = new Entry(key, value, len, now, maxAge)
|
202
331
|
|
203
332
|
// oversized objects fall out of cache automatically.
|
204
|
-
if (hit.length > this
|
205
|
-
if (this
|
333
|
+
if (hit.length > priv(this, 'max')) {
|
334
|
+
if (priv(this, 'dispose')) {
|
335
|
+
priv(this, 'dispose').call(this, key, value)
|
336
|
+
}
|
206
337
|
return false
|
207
338
|
}
|
208
339
|
|
209
|
-
this
|
210
|
-
this
|
211
|
-
this.
|
212
|
-
|
213
|
-
if (this._length > this._max)
|
214
|
-
trim(this)
|
215
|
-
|
340
|
+
priv(this, 'length', priv(this, 'length') + hit.length)
|
341
|
+
priv(this, 'lruList').unshift(hit)
|
342
|
+
priv(this, 'cache').set(key, priv(this, 'lruList').head)
|
343
|
+
trim(this)
|
216
344
|
return true
|
217
345
|
}
|
218
346
|
|
219
347
|
LRUCache.prototype.has = function (key) {
|
220
|
-
|
221
|
-
|
222
|
-
var hit = this._cache[key]
|
348
|
+
if (!priv(this, 'cache').has(key)) return false
|
349
|
+
var hit = priv(this, 'cache').get(key).value
|
223
350
|
if (isStale(this, hit)) {
|
224
351
|
return false
|
225
352
|
}
|
@@ -227,108 +354,115 @@ LRUCache.prototype.has = function (key) {
|
|
227
354
|
}
|
228
355
|
|
229
356
|
LRUCache.prototype.get = function (key) {
|
230
|
-
typeCheckKey(key)
|
231
357
|
return get(this, key, true)
|
232
358
|
}
|
233
359
|
|
234
360
|
LRUCache.prototype.peek = function (key) {
|
235
|
-
typeCheckKey(key)
|
236
361
|
return get(this, key, false)
|
237
362
|
}
|
238
363
|
|
239
364
|
LRUCache.prototype.pop = function () {
|
240
|
-
var
|
241
|
-
|
242
|
-
|
365
|
+
var node = priv(this, 'lruList').tail
|
366
|
+
if (!node) return null
|
367
|
+
del(this, node)
|
368
|
+
return node.value
|
243
369
|
}
|
244
370
|
|
245
371
|
LRUCache.prototype.del = function (key) {
|
246
|
-
|
247
|
-
del(this, this._cache[key])
|
372
|
+
del(this, priv(this, 'cache').get(key))
|
248
373
|
}
|
249
374
|
|
250
375
|
LRUCache.prototype.load = function (arr) {
|
251
|
-
//reset the cache
|
252
|
-
this.reset()
|
376
|
+
// reset the cache
|
377
|
+
this.reset()
|
253
378
|
|
254
379
|
var now = Date.now()
|
255
|
-
//A previous serialized cache has the most recent items first
|
256
|
-
for (var l = arr.length - 1; l >= 0; l--
|
380
|
+
// A previous serialized cache has the most recent items first
|
381
|
+
for (var l = arr.length - 1; l >= 0; l--) {
|
257
382
|
var hit = arr[l]
|
258
|
-
typeCheckKey(hit.k)
|
259
383
|
var expiresAt = hit.e || 0
|
260
384
|
if (expiresAt === 0) {
|
261
|
-
//the item was created without expiration in a non aged cache
|
385
|
+
// the item was created without expiration in a non aged cache
|
262
386
|
this.set(hit.k, hit.v)
|
263
387
|
} else {
|
264
388
|
var maxAge = expiresAt - now
|
265
|
-
//dont add already expired items
|
266
|
-
if (maxAge > 0)
|
389
|
+
// dont add already expired items
|
390
|
+
if (maxAge > 0) {
|
391
|
+
this.set(hit.k, hit.v, maxAge)
|
392
|
+
}
|
267
393
|
}
|
268
394
|
}
|
269
395
|
}
|
270
396
|
|
397
|
+
LRUCache.prototype.prune = function () {
|
398
|
+
var self = this
|
399
|
+
priv(this, 'cache').forEach(function (value, key) {
|
400
|
+
get(self, key, false)
|
401
|
+
})
|
402
|
+
}
|
403
|
+
|
271
404
|
function get (self, key, doUse) {
|
272
|
-
|
273
|
-
|
274
|
-
|
405
|
+
var node = priv(self, 'cache').get(key)
|
406
|
+
if (node) {
|
407
|
+
var hit = node.value
|
275
408
|
if (isStale(self, hit)) {
|
276
|
-
del(self,
|
277
|
-
if (!self
|
409
|
+
del(self, node)
|
410
|
+
if (!priv(self, 'allowStale')) hit = undefined
|
278
411
|
} else {
|
279
|
-
if (doUse)
|
412
|
+
if (doUse) {
|
413
|
+
priv(self, 'lruList').unshiftNode(node)
|
414
|
+
}
|
280
415
|
}
|
281
416
|
if (hit) hit = hit.value
|
282
417
|
}
|
283
418
|
return hit
|
284
419
|
}
|
285
420
|
|
286
|
-
function isStale(self, hit) {
|
287
|
-
if (!hit || (!hit.maxAge && !self
|
288
|
-
|
421
|
+
function isStale (self, hit) {
|
422
|
+
if (!hit || (!hit.maxAge && !priv(self, 'maxAge'))) {
|
423
|
+
return false
|
424
|
+
}
|
425
|
+
var stale = false
|
289
426
|
var diff = Date.now() - hit.now
|
290
427
|
if (hit.maxAge) {
|
291
428
|
stale = diff > hit.maxAge
|
292
429
|
} else {
|
293
|
-
stale = self
|
430
|
+
stale = priv(self, 'maxAge') && (diff > priv(self, 'maxAge'))
|
294
431
|
}
|
295
|
-
return stale
|
296
|
-
}
|
297
|
-
|
298
|
-
function use (self, hit) {
|
299
|
-
shiftLU(self, hit)
|
300
|
-
hit.lu = self._mru ++
|
301
|
-
self._lruList[hit.lu] = hit
|
432
|
+
return stale
|
302
433
|
}
|
303
434
|
|
304
435
|
function trim (self) {
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
436
|
+
if (priv(self, 'length') > priv(self, 'max')) {
|
437
|
+
for (var walker = priv(self, 'lruList').tail;
|
438
|
+
priv(self, 'length') > priv(self, 'max') && walker !== null;) {
|
439
|
+
// We know that we're about to delete this one, and also
|
440
|
+
// what the next least recently used key will be, so just
|
441
|
+
// go ahead and set it now.
|
442
|
+
var prev = walker.prev
|
443
|
+
del(self, walker)
|
444
|
+
walker = prev
|
445
|
+
}
|
446
|
+
}
|
312
447
|
}
|
313
448
|
|
314
|
-
function del (self,
|
315
|
-
if (
|
316
|
-
|
317
|
-
self
|
318
|
-
|
319
|
-
|
320
|
-
|
449
|
+
function del (self, node) {
|
450
|
+
if (node) {
|
451
|
+
var hit = node.value
|
452
|
+
if (priv(self, 'dispose')) {
|
453
|
+
priv(self, 'dispose').call(this, hit.key, hit.value)
|
454
|
+
}
|
455
|
+
priv(self, 'length', priv(self, 'length') - hit.length)
|
456
|
+
priv(self, 'cache').delete(hit.key)
|
457
|
+
priv(self, 'lruList').removeNode(node)
|
321
458
|
}
|
322
459
|
}
|
323
460
|
|
324
461
|
// classy, since V8 prefers predictable objects.
|
325
|
-
function Entry (key, value,
|
462
|
+
function Entry (key, value, length, now, maxAge) {
|
326
463
|
this.key = key
|
327
464
|
this.value = value
|
328
|
-
this.lu = lu
|
329
465
|
this.length = length
|
330
466
|
this.now = now
|
331
|
-
|
467
|
+
this.maxAge = maxAge || 0
|
332
468
|
}
|
333
|
-
|
334
|
-
})()
|
@@ -0,0 +1,15 @@
|
|
1
|
+
The ISC License
|
2
|
+
|
3
|
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
4
|
+
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
15
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|