@common.js/quick-lru 6.1.1 → 7.0.0
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.
- package/README.md +1 -1
- package/index.d.ts +14 -8
- package/index.js +381 -288
- package/package.json +8 -8
- package/readme.md +0 -157
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
The [quick-lru](https://www.npmjs.com/package/quick-lru) package exported as CommonJS modules.
|
|
4
4
|
|
|
5
|
-
Exported from [quick-lru@
|
|
5
|
+
Exported from [quick-lru@7.0.0](https://www.npmjs.com/package/quick-lru/v/7.0.0) using https://github.com/etienne-martin/common.js.
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Options<KeyType, ValueType> = {
|
|
2
2
|
/**
|
|
3
3
|
The maximum number of milliseconds an item should remain in the cache.
|
|
4
4
|
|
|
@@ -22,14 +22,10 @@ export interface Options<KeyType, ValueType> {
|
|
|
22
22
|
Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
|
|
23
23
|
*/
|
|
24
24
|
onEviction?: (key: KeyType, value: ValueType) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default class QuickLRU<KeyType, ValueType> extends Map implements Iterable<[KeyType, ValueType]> {
|
|
28
|
-
/**
|
|
29
|
-
The stored item count.
|
|
30
|
-
*/
|
|
31
|
-
readonly size: number;
|
|
25
|
+
};
|
|
32
26
|
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
+
export default class QuickLRU<KeyType, ValueType> extends Map<KeyType, ValueType> implements Iterable<[KeyType, ValueType]> {
|
|
33
29
|
/**
|
|
34
30
|
Simple ["Least Recently Used" (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29).
|
|
35
31
|
|
|
@@ -101,6 +97,16 @@ export default class QuickLRU<KeyType, ValueType> extends Map implements Iterabl
|
|
|
101
97
|
*/
|
|
102
98
|
resize(maxSize: number): void;
|
|
103
99
|
|
|
100
|
+
/**
|
|
101
|
+
The stored item count.
|
|
102
|
+
*/
|
|
103
|
+
get size(): number;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
The set max size.
|
|
107
|
+
*/
|
|
108
|
+
get maxSize(): number;
|
|
109
|
+
|
|
104
110
|
/**
|
|
105
111
|
Iterable for all the keys.
|
|
106
112
|
*/
|
package/index.js
CHANGED
|
@@ -25,11 +25,85 @@ function _assertThisInitialized(self) {
|
|
|
25
25
|
}
|
|
26
26
|
return self;
|
|
27
27
|
}
|
|
28
|
+
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
29
|
+
if (privateCollection.has(obj)) {
|
|
30
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
34
|
+
if (descriptor.get) {
|
|
35
|
+
return descriptor.get.call(receiver);
|
|
36
|
+
}
|
|
37
|
+
return descriptor.value;
|
|
38
|
+
}
|
|
39
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
40
|
+
if (descriptor.set) {
|
|
41
|
+
descriptor.set.call(receiver, value);
|
|
42
|
+
} else {
|
|
43
|
+
if (!descriptor.writable) {
|
|
44
|
+
throw new TypeError("attempted to set read only private field");
|
|
45
|
+
}
|
|
46
|
+
descriptor.value = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function _classApplyDescriptorUpdate(receiver, descriptor) {
|
|
50
|
+
if (descriptor.set) {
|
|
51
|
+
if (!("__destrWrapper" in descriptor)) {
|
|
52
|
+
descriptor.__destrWrapper = {
|
|
53
|
+
set value (v){
|
|
54
|
+
descriptor.set.call(receiver, v);
|
|
55
|
+
},
|
|
56
|
+
get value () {
|
|
57
|
+
return descriptor.get.call(receiver);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return descriptor.__destrWrapper;
|
|
62
|
+
} else {
|
|
63
|
+
if (!descriptor.writable) {
|
|
64
|
+
throw new TypeError("attempted to set read only private field");
|
|
65
|
+
}
|
|
66
|
+
return descriptor;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
28
69
|
function _classCallCheck(instance, Constructor) {
|
|
29
70
|
if (!(instance instanceof Constructor)) {
|
|
30
71
|
throw new TypeError("Cannot call a class as a function");
|
|
31
72
|
}
|
|
32
73
|
}
|
|
74
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
75
|
+
if (!privateMap.has(receiver)) {
|
|
76
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
77
|
+
}
|
|
78
|
+
return privateMap.get(receiver);
|
|
79
|
+
}
|
|
80
|
+
function _classPrivateFieldGet(receiver, privateMap) {
|
|
81
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
82
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
83
|
+
}
|
|
84
|
+
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
85
|
+
_checkPrivateRedeclaration(obj, privateMap);
|
|
86
|
+
privateMap.set(obj, value);
|
|
87
|
+
}
|
|
88
|
+
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
89
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
90
|
+
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
function _classPrivateFieldUpdate(receiver, privateMap) {
|
|
94
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "update");
|
|
95
|
+
return _classApplyDescriptorUpdate(receiver, descriptor);
|
|
96
|
+
}
|
|
97
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
98
|
+
if (!privateSet.has(receiver)) {
|
|
99
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
100
|
+
}
|
|
101
|
+
return fn;
|
|
102
|
+
}
|
|
103
|
+
function _classPrivateMethodInit(obj, privateSet) {
|
|
104
|
+
_checkPrivateRedeclaration(obj, privateSet);
|
|
105
|
+
privateSet.add(obj);
|
|
106
|
+
}
|
|
33
107
|
function isNativeReflectConstruct() {
|
|
34
108
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
35
109
|
if (Reflect.construct.sham) return false;
|
|
@@ -226,10 +300,10 @@ var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
|
226
300
|
return this;
|
|
227
301
|
}), g;
|
|
228
302
|
function verb(n) {
|
|
229
|
-
return function(
|
|
303
|
+
return function(v1) {
|
|
230
304
|
return step([
|
|
231
305
|
n,
|
|
232
|
-
|
|
306
|
+
v1
|
|
233
307
|
]);
|
|
234
308
|
};
|
|
235
309
|
}
|
|
@@ -303,6 +377,8 @@ var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
|
303
377
|
};
|
|
304
378
|
}
|
|
305
379
|
};
|
|
380
|
+
var _size = /*#__PURE__*/ new WeakMap(), _cache = /*#__PURE__*/ new WeakMap(), _oldCache = /*#__PURE__*/ new WeakMap(), _maxSize = /*#__PURE__*/ new WeakMap(), _maxAge = /*#__PURE__*/ new WeakMap(), _onEviction = /*#__PURE__*/ new WeakMap(), _emitEvictions = /*#__PURE__*/ new WeakSet(), _deleteIfExpired = /*#__PURE__*/ new WeakSet(), _getOrDeleteIfExpired = /*#__PURE__*/ new WeakSet(), _getItemValue = /*#__PURE__*/ new WeakSet(), _peek = /*#__PURE__*/ new WeakSet(), _set = /*#__PURE__*/ new WeakSet(), _moveToRecent = /*#__PURE__*/ new WeakSet(), _entriesAscending = /*#__PURE__*/ new WeakSet();
|
|
381
|
+
var _iterator = Symbol.iterator, _toStringTag = Symbol.toStringTag;
|
|
306
382
|
var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
307
383
|
"use strict";
|
|
308
384
|
_inherits(QuickLRU, Map1);
|
|
@@ -312,260 +388,68 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
312
388
|
_classCallCheck(this, QuickLRU);
|
|
313
389
|
var _this;
|
|
314
390
|
_this = _super.call(this);
|
|
391
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _emitEvictions);
|
|
392
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _deleteIfExpired);
|
|
393
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _getOrDeleteIfExpired);
|
|
394
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _getItemValue);
|
|
395
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _peek);
|
|
396
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _set);
|
|
397
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _moveToRecent);
|
|
398
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _entriesAscending);
|
|
399
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _size, {
|
|
400
|
+
writable: true,
|
|
401
|
+
value: 0
|
|
402
|
+
});
|
|
403
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _cache, {
|
|
404
|
+
writable: true,
|
|
405
|
+
value: new Map()
|
|
406
|
+
});
|
|
407
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _oldCache, {
|
|
408
|
+
writable: true,
|
|
409
|
+
value: new Map()
|
|
410
|
+
});
|
|
411
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _maxSize, {
|
|
412
|
+
writable: true,
|
|
413
|
+
value: void 0
|
|
414
|
+
});
|
|
415
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _maxAge, {
|
|
416
|
+
writable: true,
|
|
417
|
+
value: void 0
|
|
418
|
+
});
|
|
419
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _onEviction, {
|
|
420
|
+
writable: true,
|
|
421
|
+
value: void 0
|
|
422
|
+
});
|
|
315
423
|
if (!(options.maxSize && options.maxSize > 0)) {
|
|
316
424
|
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
317
425
|
}
|
|
318
426
|
if (typeof options.maxAge === "number" && options.maxAge === 0) {
|
|
319
427
|
throw new TypeError("`maxAge` must be a number greater than 0");
|
|
320
428
|
}
|
|
321
|
-
|
|
322
|
-
_this
|
|
323
|
-
_this
|
|
324
|
-
_this.onEviction = options.onEviction;
|
|
325
|
-
_this.cache = new Map();
|
|
326
|
-
_this.oldCache = new Map();
|
|
327
|
-
_this._size = 0;
|
|
429
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _maxSize, options.maxSize);
|
|
430
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _maxAge, options.maxAge || Number.POSITIVE_INFINITY);
|
|
431
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _onEviction, options.onEviction);
|
|
328
432
|
return _this;
|
|
329
433
|
}
|
|
330
434
|
_createClass(QuickLRU, [
|
|
331
435
|
{
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
339
|
-
try {
|
|
340
|
-
for(var _iterator = cache[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
341
|
-
var _value = _slicedToArray(_step.value, 2), key = _value[0], item = _value[1];
|
|
342
|
-
this.onEviction(key, item.value);
|
|
343
|
-
}
|
|
344
|
-
} catch (err) {
|
|
345
|
-
_didIteratorError = true;
|
|
346
|
-
_iteratorError = err;
|
|
347
|
-
} finally{
|
|
348
|
-
try {
|
|
349
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
350
|
-
_iterator.return();
|
|
351
|
-
}
|
|
352
|
-
} finally{
|
|
353
|
-
if (_didIteratorError) {
|
|
354
|
-
throw _iteratorError;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
key: "_deleteIfExpired",
|
|
362
|
-
value: function _deleteIfExpired(key, item) {
|
|
363
|
-
if (typeof item.expiry === "number" && item.expiry <= Date.now()) {
|
|
364
|
-
if (typeof this.onEviction === "function") {
|
|
365
|
-
this.onEviction(key, item.value);
|
|
366
|
-
}
|
|
367
|
-
return this.delete(key);
|
|
368
|
-
}
|
|
369
|
-
return false;
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
key: "_getOrDeleteIfExpired",
|
|
374
|
-
value: function _getOrDeleteIfExpired(key, item) {
|
|
375
|
-
var deleted = this._deleteIfExpired(key, item);
|
|
376
|
-
if (deleted === false) {
|
|
377
|
-
return item.value;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
key: "_getItemValue",
|
|
383
|
-
value: function _getItemValue(key, item) {
|
|
384
|
-
return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
{
|
|
388
|
-
key: "_peek",
|
|
389
|
-
value: function _peek(key, cache) {
|
|
390
|
-
var item = cache.get(key);
|
|
391
|
-
return this._getItemValue(key, item);
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
key: "_set",
|
|
396
|
-
value: function _set(key, value) {
|
|
397
|
-
this.cache.set(key, value);
|
|
398
|
-
this._size++;
|
|
399
|
-
if (this._size >= this.maxSize) {
|
|
400
|
-
this._size = 0;
|
|
401
|
-
this._emitEvictions(this.oldCache);
|
|
402
|
-
this.oldCache = this.cache;
|
|
403
|
-
this.cache = new Map();
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
key: "_moveToRecent",
|
|
409
|
-
value: function _moveToRecent(key, item) {
|
|
410
|
-
this.oldCache.delete(key);
|
|
411
|
-
this._set(key, item);
|
|
412
|
-
}
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
key: "_entriesAscending",
|
|
416
|
-
value: function _entriesAscending() {
|
|
417
|
-
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, _item, key, value, deleted, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item1, _item1, key1, value1, deleted1, err;
|
|
418
|
-
return __generator(this, function(_state) {
|
|
419
|
-
switch(_state.label){
|
|
420
|
-
case 0:
|
|
421
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
422
|
-
_state.label = 1;
|
|
423
|
-
case 1:
|
|
424
|
-
_state.trys.push([
|
|
425
|
-
1,
|
|
426
|
-
6,
|
|
427
|
-
7,
|
|
428
|
-
8
|
|
429
|
-
]);
|
|
430
|
-
_iterator = this.oldCache[Symbol.iterator]();
|
|
431
|
-
_state.label = 2;
|
|
432
|
-
case 2:
|
|
433
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
434
|
-
3,
|
|
435
|
-
5
|
|
436
|
-
];
|
|
437
|
-
item = _step.value;
|
|
438
|
-
_item = _slicedToArray(item, 2), key = _item[0], value = _item[1];
|
|
439
|
-
if (!!this.cache.has(key)) return [
|
|
440
|
-
3,
|
|
441
|
-
4
|
|
442
|
-
];
|
|
443
|
-
deleted = this._deleteIfExpired(key, value);
|
|
444
|
-
if (!(deleted === false)) return [
|
|
445
|
-
3,
|
|
446
|
-
4
|
|
447
|
-
];
|
|
448
|
-
return [
|
|
449
|
-
4,
|
|
450
|
-
item
|
|
451
|
-
];
|
|
452
|
-
case 3:
|
|
453
|
-
_state.sent();
|
|
454
|
-
_state.label = 4;
|
|
455
|
-
case 4:
|
|
456
|
-
_iteratorNormalCompletion = true;
|
|
457
|
-
return [
|
|
458
|
-
3,
|
|
459
|
-
2
|
|
460
|
-
];
|
|
461
|
-
case 5:
|
|
462
|
-
return [
|
|
463
|
-
3,
|
|
464
|
-
8
|
|
465
|
-
];
|
|
466
|
-
case 6:
|
|
467
|
-
err = _state.sent();
|
|
468
|
-
_didIteratorError = true;
|
|
469
|
-
_iteratorError = err;
|
|
470
|
-
return [
|
|
471
|
-
3,
|
|
472
|
-
8
|
|
473
|
-
];
|
|
474
|
-
case 7:
|
|
475
|
-
try {
|
|
476
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
477
|
-
_iterator.return();
|
|
478
|
-
}
|
|
479
|
-
} finally{
|
|
480
|
-
if (_didIteratorError) {
|
|
481
|
-
throw _iteratorError;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return [
|
|
485
|
-
7
|
|
486
|
-
];
|
|
487
|
-
case 8:
|
|
488
|
-
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
489
|
-
_state.label = 9;
|
|
490
|
-
case 9:
|
|
491
|
-
_state.trys.push([
|
|
492
|
-
9,
|
|
493
|
-
14,
|
|
494
|
-
15,
|
|
495
|
-
16
|
|
496
|
-
]);
|
|
497
|
-
_iterator1 = this.cache[Symbol.iterator]();
|
|
498
|
-
_state.label = 10;
|
|
499
|
-
case 10:
|
|
500
|
-
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
|
|
501
|
-
3,
|
|
502
|
-
13
|
|
503
|
-
];
|
|
504
|
-
item1 = _step1.value;
|
|
505
|
-
_item1 = _slicedToArray(item1, 2), key1 = _item1[0], value1 = _item1[1];
|
|
506
|
-
deleted1 = this._deleteIfExpired(key1, value1);
|
|
507
|
-
if (!(deleted1 === false)) return [
|
|
508
|
-
3,
|
|
509
|
-
12
|
|
510
|
-
];
|
|
511
|
-
return [
|
|
512
|
-
4,
|
|
513
|
-
item1
|
|
514
|
-
];
|
|
515
|
-
case 11:
|
|
516
|
-
_state.sent();
|
|
517
|
-
_state.label = 12;
|
|
518
|
-
case 12:
|
|
519
|
-
_iteratorNormalCompletion1 = true;
|
|
520
|
-
return [
|
|
521
|
-
3,
|
|
522
|
-
10
|
|
523
|
-
];
|
|
524
|
-
case 13:
|
|
525
|
-
return [
|
|
526
|
-
3,
|
|
527
|
-
16
|
|
528
|
-
];
|
|
529
|
-
case 14:
|
|
530
|
-
err = _state.sent();
|
|
531
|
-
_didIteratorError1 = true;
|
|
532
|
-
_iteratorError1 = err;
|
|
533
|
-
return [
|
|
534
|
-
3,
|
|
535
|
-
16
|
|
536
|
-
];
|
|
537
|
-
case 15:
|
|
538
|
-
try {
|
|
539
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
540
|
-
_iterator1.return();
|
|
541
|
-
}
|
|
542
|
-
} finally{
|
|
543
|
-
if (_didIteratorError1) {
|
|
544
|
-
throw _iteratorError1;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return [
|
|
548
|
-
7
|
|
549
|
-
];
|
|
550
|
-
case 16:
|
|
551
|
-
return [
|
|
552
|
-
2
|
|
553
|
-
];
|
|
554
|
-
}
|
|
555
|
-
});
|
|
436
|
+
key: "__oldCache",
|
|
437
|
+
get: // For tests.
|
|
438
|
+
function get() {
|
|
439
|
+
return _classPrivateFieldGet(this, _oldCache);
|
|
556
440
|
}
|
|
557
441
|
},
|
|
558
442
|
{
|
|
559
443
|
key: "get",
|
|
560
444
|
value: function get(key) {
|
|
561
|
-
if (this.
|
|
562
|
-
var item = this.
|
|
563
|
-
return this.
|
|
445
|
+
if (_classPrivateFieldGet(this, _cache).has(key)) {
|
|
446
|
+
var item = _classPrivateFieldGet(this, _cache).get(key);
|
|
447
|
+
return _classPrivateMethodGet(this, _getItemValue, getItemValue).call(this, key, item);
|
|
564
448
|
}
|
|
565
|
-
if (this.
|
|
566
|
-
var item1 = this.
|
|
567
|
-
if (this.
|
|
568
|
-
this.
|
|
449
|
+
if (_classPrivateFieldGet(this, _oldCache).has(key)) {
|
|
450
|
+
var item1 = _classPrivateFieldGet(this, _oldCache).get(key);
|
|
451
|
+
if (_classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key, item1) === false) {
|
|
452
|
+
_classPrivateMethodGet(this, _moveToRecent, moveToRecent).call(this, key, item1);
|
|
569
453
|
return item1.value;
|
|
570
454
|
}
|
|
571
455
|
}
|
|
@@ -573,61 +457,62 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
573
457
|
},
|
|
574
458
|
{
|
|
575
459
|
key: "set",
|
|
576
|
-
value: function
|
|
577
|
-
var ref = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {},
|
|
460
|
+
value: function set1(key, value) {
|
|
461
|
+
var ref = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, _maxAge1 = ref.maxAge, maxAge = _maxAge1 === void 0 ? _classPrivateFieldGet(this, _maxAge) : _maxAge1;
|
|
578
462
|
var expiry = typeof maxAge === "number" && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : undefined;
|
|
579
|
-
if (this.
|
|
580
|
-
this.
|
|
463
|
+
if (_classPrivateFieldGet(this, _cache).has(key)) {
|
|
464
|
+
_classPrivateFieldGet(this, _cache).set(key, {
|
|
581
465
|
value: value,
|
|
582
466
|
expiry: expiry
|
|
583
467
|
});
|
|
584
468
|
} else {
|
|
585
|
-
this.
|
|
469
|
+
_classPrivateMethodGet(this, _set, set).call(this, key, {
|
|
586
470
|
value: value,
|
|
587
471
|
expiry: expiry
|
|
588
472
|
});
|
|
589
473
|
}
|
|
474
|
+
return this;
|
|
590
475
|
}
|
|
591
476
|
},
|
|
592
477
|
{
|
|
593
478
|
key: "has",
|
|
594
479
|
value: function has(key) {
|
|
595
|
-
if (this.
|
|
596
|
-
return !this.
|
|
480
|
+
if (_classPrivateFieldGet(this, _cache).has(key)) {
|
|
481
|
+
return !_classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key, _classPrivateFieldGet(this, _cache).get(key));
|
|
597
482
|
}
|
|
598
|
-
if (this.
|
|
599
|
-
return !this.
|
|
483
|
+
if (_classPrivateFieldGet(this, _oldCache).has(key)) {
|
|
484
|
+
return !_classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key, _classPrivateFieldGet(this, _oldCache).get(key));
|
|
600
485
|
}
|
|
601
486
|
return false;
|
|
602
487
|
}
|
|
603
488
|
},
|
|
604
489
|
{
|
|
605
490
|
key: "peek",
|
|
606
|
-
value: function
|
|
607
|
-
if (this.
|
|
608
|
-
return this.
|
|
491
|
+
value: function peek1(key) {
|
|
492
|
+
if (_classPrivateFieldGet(this, _cache).has(key)) {
|
|
493
|
+
return _classPrivateMethodGet(this, _peek, peek).call(this, key, _classPrivateFieldGet(this, _cache));
|
|
609
494
|
}
|
|
610
|
-
if (this.
|
|
611
|
-
return this.
|
|
495
|
+
if (_classPrivateFieldGet(this, _oldCache).has(key)) {
|
|
496
|
+
return _classPrivateMethodGet(this, _peek, peek).call(this, key, _classPrivateFieldGet(this, _oldCache));
|
|
612
497
|
}
|
|
613
498
|
}
|
|
614
499
|
},
|
|
615
500
|
{
|
|
616
501
|
key: "delete",
|
|
617
502
|
value: function _delete(key) {
|
|
618
|
-
var deleted = this.
|
|
503
|
+
var deleted = _classPrivateFieldGet(this, _cache).delete(key);
|
|
619
504
|
if (deleted) {
|
|
620
|
-
this.
|
|
505
|
+
_classPrivateFieldUpdate(this, _size).value--;
|
|
621
506
|
}
|
|
622
|
-
return this.
|
|
507
|
+
return _classPrivateFieldGet(this, _oldCache).delete(key) || deleted;
|
|
623
508
|
}
|
|
624
509
|
},
|
|
625
510
|
{
|
|
626
511
|
key: "clear",
|
|
627
512
|
value: function clear() {
|
|
628
|
-
this.
|
|
629
|
-
this.
|
|
630
|
-
this
|
|
513
|
+
_classPrivateFieldGet(this, _cache).clear();
|
|
514
|
+
_classPrivateFieldGet(this, _oldCache).clear();
|
|
515
|
+
_classPrivateFieldSet(this, _size, 0);
|
|
631
516
|
}
|
|
632
517
|
},
|
|
633
518
|
{
|
|
@@ -636,21 +521,21 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
636
521
|
if (!(newSize && newSize > 0)) {
|
|
637
522
|
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
638
523
|
}
|
|
639
|
-
var items = _toConsumableArray(this.
|
|
524
|
+
var items = _toConsumableArray(_classPrivateMethodGet(this, _entriesAscending, entriesAscending).call(this));
|
|
640
525
|
var removeCount = items.length - newSize;
|
|
641
526
|
if (removeCount < 0) {
|
|
642
|
-
this
|
|
643
|
-
this
|
|
644
|
-
this
|
|
527
|
+
_classPrivateFieldSet(this, _cache, new Map(items));
|
|
528
|
+
_classPrivateFieldSet(this, _oldCache, new Map());
|
|
529
|
+
_classPrivateFieldSet(this, _size, items.length);
|
|
645
530
|
} else {
|
|
646
531
|
if (removeCount > 0) {
|
|
647
|
-
this.
|
|
532
|
+
_classPrivateMethodGet(this, _emitEvictions, emitEvictions).call(this, items.slice(0, removeCount));
|
|
648
533
|
}
|
|
649
|
-
this
|
|
650
|
-
this
|
|
651
|
-
this
|
|
534
|
+
_classPrivateFieldSet(this, _oldCache, new Map(items.slice(removeCount)));
|
|
535
|
+
_classPrivateFieldSet(this, _cache, new Map());
|
|
536
|
+
_classPrivateFieldSet(this, _size, 0);
|
|
652
537
|
}
|
|
653
|
-
this
|
|
538
|
+
_classPrivateFieldSet(this, _maxSize, newSize);
|
|
654
539
|
}
|
|
655
540
|
},
|
|
656
541
|
{
|
|
@@ -796,7 +681,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
796
681
|
}
|
|
797
682
|
},
|
|
798
683
|
{
|
|
799
|
-
key:
|
|
684
|
+
key: _iterator,
|
|
800
685
|
value: function value() {
|
|
801
686
|
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, _item, key, value1, deleted, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item1, _item1, key1, value2, deleted1, err;
|
|
802
687
|
return __generator(this, function(_state) {
|
|
@@ -811,7 +696,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
811
696
|
7,
|
|
812
697
|
8
|
|
813
698
|
]);
|
|
814
|
-
_iterator = this
|
|
699
|
+
_iterator = _classPrivateFieldGet(this, _cache)[Symbol.iterator]();
|
|
815
700
|
_state.label = 2;
|
|
816
701
|
case 2:
|
|
817
702
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
@@ -820,7 +705,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
820
705
|
];
|
|
821
706
|
item = _step.value;
|
|
822
707
|
_item = _slicedToArray(item, 2), key = _item[0], value1 = _item[1];
|
|
823
|
-
deleted = this.
|
|
708
|
+
deleted = _classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key, value1);
|
|
824
709
|
if (!(deleted === false)) return [
|
|
825
710
|
3,
|
|
826
711
|
4
|
|
@@ -877,7 +762,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
877
762
|
15,
|
|
878
763
|
16
|
|
879
764
|
]);
|
|
880
|
-
_iterator1 = this
|
|
765
|
+
_iterator1 = _classPrivateFieldGet(this, _oldCache)[Symbol.iterator]();
|
|
881
766
|
_state.label = 10;
|
|
882
767
|
case 10:
|
|
883
768
|
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
|
|
@@ -886,11 +771,11 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
886
771
|
];
|
|
887
772
|
item1 = _step1.value;
|
|
888
773
|
_item1 = _slicedToArray(item1, 2), key1 = _item1[0], value2 = _item1[1];
|
|
889
|
-
if (!!this.
|
|
774
|
+
if (!!_classPrivateFieldGet(this, _cache).has(key1)) return [
|
|
890
775
|
3,
|
|
891
776
|
12
|
|
892
777
|
];
|
|
893
|
-
deleted1 = this.
|
|
778
|
+
deleted1 = _classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key1, value2);
|
|
894
779
|
if (!(deleted1 === false)) return [
|
|
895
780
|
3,
|
|
896
781
|
12
|
|
@@ -952,7 +837,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
952
837
|
return __generator(this, function(_state) {
|
|
953
838
|
switch(_state.label){
|
|
954
839
|
case 0:
|
|
955
|
-
items = _toConsumableArray(this
|
|
840
|
+
items = _toConsumableArray(_classPrivateFieldGet(this, _cache));
|
|
956
841
|
i = items.length - 1;
|
|
957
842
|
_state.label = 1;
|
|
958
843
|
case 1:
|
|
@@ -962,7 +847,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
962
847
|
];
|
|
963
848
|
item = items[i];
|
|
964
849
|
_item = _slicedToArray(item, 2), key = _item[0], value = _item[1];
|
|
965
|
-
deleted = this.
|
|
850
|
+
deleted = _classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key, value);
|
|
966
851
|
if (!(deleted === false)) return [
|
|
967
852
|
3,
|
|
968
853
|
3
|
|
@@ -984,7 +869,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
984
869
|
1
|
|
985
870
|
];
|
|
986
871
|
case 4:
|
|
987
|
-
items = _toConsumableArray(this
|
|
872
|
+
items = _toConsumableArray(_classPrivateFieldGet(this, _oldCache));
|
|
988
873
|
i1 = items.length - 1;
|
|
989
874
|
_state.label = 5;
|
|
990
875
|
case 5:
|
|
@@ -994,11 +879,11 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
994
879
|
];
|
|
995
880
|
item1 = items[i1];
|
|
996
881
|
_item1 = _slicedToArray(item1, 2), key1 = _item1[0], value1 = _item1[1];
|
|
997
|
-
if (!!this.
|
|
882
|
+
if (!!_classPrivateFieldGet(this, _cache).has(key1)) return [
|
|
998
883
|
3,
|
|
999
884
|
7
|
|
1000
885
|
];
|
|
1001
|
-
deleted1 = this.
|
|
886
|
+
deleted1 = _classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key1, value1);
|
|
1002
887
|
if (!(deleted1 === false)) return [
|
|
1003
888
|
3,
|
|
1004
889
|
7
|
|
@@ -1029,7 +914,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
1029
914
|
},
|
|
1030
915
|
{
|
|
1031
916
|
key: "entriesAscending",
|
|
1032
|
-
value: function
|
|
917
|
+
value: function entriesAscending1() {
|
|
1033
918
|
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, key, value, err;
|
|
1034
919
|
return __generator(this, function(_state) {
|
|
1035
920
|
switch(_state.label){
|
|
@@ -1043,7 +928,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
1043
928
|
7,
|
|
1044
929
|
8
|
|
1045
930
|
]);
|
|
1046
|
-
_iterator = this.
|
|
931
|
+
_iterator = _classPrivateMethodGet(this, _entriesAscending, entriesAscending).call(this)[Symbol.iterator]();
|
|
1047
932
|
_state.label = 2;
|
|
1048
933
|
case 2:
|
|
1049
934
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
@@ -1104,15 +989,15 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
1104
989
|
{
|
|
1105
990
|
key: "size",
|
|
1106
991
|
get: function get() {
|
|
1107
|
-
if (!this
|
|
1108
|
-
return this.
|
|
992
|
+
if (!_classPrivateFieldGet(this, _size)) {
|
|
993
|
+
return _classPrivateFieldGet(this, _oldCache).size;
|
|
1109
994
|
}
|
|
1110
995
|
var oldCacheSize = 0;
|
|
1111
996
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1112
997
|
try {
|
|
1113
|
-
for(var _iterator = this.
|
|
998
|
+
for(var _iterator = _classPrivateFieldGet(this, _oldCache).keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1114
999
|
var key = _step.value;
|
|
1115
|
-
if (!this.
|
|
1000
|
+
if (!_classPrivateFieldGet(this, _cache).has(key)) {
|
|
1116
1001
|
oldCacheSize++;
|
|
1117
1002
|
}
|
|
1118
1003
|
}
|
|
@@ -1130,7 +1015,13 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
1130
1015
|
}
|
|
1131
1016
|
}
|
|
1132
1017
|
}
|
|
1133
|
-
return Math.min(this
|
|
1018
|
+
return Math.min(_classPrivateFieldGet(this, _size) + oldCacheSize, _classPrivateFieldGet(this, _maxSize));
|
|
1019
|
+
}
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
key: "maxSize",
|
|
1023
|
+
get: function get() {
|
|
1024
|
+
return _classPrivateFieldGet(this, _maxSize);
|
|
1134
1025
|
}
|
|
1135
1026
|
},
|
|
1136
1027
|
{
|
|
@@ -1166,7 +1057,7 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
1166
1057
|
}
|
|
1167
1058
|
},
|
|
1168
1059
|
{
|
|
1169
|
-
key:
|
|
1060
|
+
key: _toStringTag,
|
|
1170
1061
|
get: function get() {
|
|
1171
1062
|
return JSON.stringify(_toConsumableArray(this.entriesAscending()));
|
|
1172
1063
|
}
|
|
@@ -1174,3 +1065,205 @@ var QuickLRU = /*#__PURE__*/ function(Map1) {
|
|
|
1174
1065
|
]);
|
|
1175
1066
|
return QuickLRU;
|
|
1176
1067
|
}(_wrapNativeSuper(Map));
|
|
1068
|
+
function emitEvictions(cache) {
|
|
1069
|
+
if (typeof _classPrivateFieldGet(this, _onEviction) !== "function") {
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1073
|
+
try {
|
|
1074
|
+
for(var _iterator = cache[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1075
|
+
var _value = _slicedToArray(_step.value, 2), key = _value[0], item = _value[1];
|
|
1076
|
+
_classPrivateFieldGet(this, _onEviction).call(this, key, item.value);
|
|
1077
|
+
}
|
|
1078
|
+
} catch (err) {
|
|
1079
|
+
_didIteratorError = true;
|
|
1080
|
+
_iteratorError = err;
|
|
1081
|
+
} finally{
|
|
1082
|
+
try {
|
|
1083
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1084
|
+
_iterator.return();
|
|
1085
|
+
}
|
|
1086
|
+
} finally{
|
|
1087
|
+
if (_didIteratorError) {
|
|
1088
|
+
throw _iteratorError;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
function deleteIfExpired(key, item) {
|
|
1094
|
+
if (typeof item.expiry === "number" && item.expiry <= Date.now()) {
|
|
1095
|
+
if (typeof _classPrivateFieldGet(this, _onEviction) === "function") {
|
|
1096
|
+
_classPrivateFieldGet(this, _onEviction).call(this, key, item.value);
|
|
1097
|
+
}
|
|
1098
|
+
return this.delete(key);
|
|
1099
|
+
}
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
function getOrDeleteIfExpired(key, item) {
|
|
1103
|
+
var deleted = _classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key, item);
|
|
1104
|
+
if (deleted === false) {
|
|
1105
|
+
return item.value;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
function getItemValue(key, item) {
|
|
1109
|
+
return item.expiry ? _classPrivateMethodGet(this, _getOrDeleteIfExpired, getOrDeleteIfExpired).call(this, key, item) : item.value;
|
|
1110
|
+
}
|
|
1111
|
+
function peek(key, cache) {
|
|
1112
|
+
var item = cache.get(key);
|
|
1113
|
+
return _classPrivateMethodGet(this, _getItemValue, getItemValue).call(this, key, item);
|
|
1114
|
+
}
|
|
1115
|
+
function set(key, value) {
|
|
1116
|
+
_classPrivateFieldGet(this, _cache).set(key, value);
|
|
1117
|
+
_classPrivateFieldUpdate(this, _size).value++;
|
|
1118
|
+
if (_classPrivateFieldGet(this, _size) >= _classPrivateFieldGet(this, _maxSize)) {
|
|
1119
|
+
_classPrivateFieldSet(this, _size, 0);
|
|
1120
|
+
_classPrivateMethodGet(this, _emitEvictions, emitEvictions).call(this, _classPrivateFieldGet(this, _oldCache));
|
|
1121
|
+
_classPrivateFieldSet(this, _oldCache, _classPrivateFieldGet(this, _cache));
|
|
1122
|
+
_classPrivateFieldSet(this, _cache, new Map());
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
function moveToRecent(key, item) {
|
|
1126
|
+
_classPrivateFieldGet(this, _oldCache).delete(key);
|
|
1127
|
+
_classPrivateMethodGet(this, _set, set).call(this, key, item);
|
|
1128
|
+
}
|
|
1129
|
+
function entriesAscending() {
|
|
1130
|
+
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, _item, key, value, deleted, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item1, _item1, key1, value1, deleted1, err;
|
|
1131
|
+
return __generator(this, function(_state) {
|
|
1132
|
+
switch(_state.label){
|
|
1133
|
+
case 0:
|
|
1134
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1135
|
+
_state.label = 1;
|
|
1136
|
+
case 1:
|
|
1137
|
+
_state.trys.push([
|
|
1138
|
+
1,
|
|
1139
|
+
6,
|
|
1140
|
+
7,
|
|
1141
|
+
8
|
|
1142
|
+
]);
|
|
1143
|
+
_iterator = _classPrivateFieldGet(this, _oldCache)[Symbol.iterator]();
|
|
1144
|
+
_state.label = 2;
|
|
1145
|
+
case 2:
|
|
1146
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
1147
|
+
3,
|
|
1148
|
+
5
|
|
1149
|
+
];
|
|
1150
|
+
item = _step.value;
|
|
1151
|
+
_item = _slicedToArray(item, 2), key = _item[0], value = _item[1];
|
|
1152
|
+
if (!!_classPrivateFieldGet(this, _cache).has(key)) return [
|
|
1153
|
+
3,
|
|
1154
|
+
4
|
|
1155
|
+
];
|
|
1156
|
+
deleted = _classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key, value);
|
|
1157
|
+
if (!(deleted === false)) return [
|
|
1158
|
+
3,
|
|
1159
|
+
4
|
|
1160
|
+
];
|
|
1161
|
+
return [
|
|
1162
|
+
4,
|
|
1163
|
+
item
|
|
1164
|
+
];
|
|
1165
|
+
case 3:
|
|
1166
|
+
_state.sent();
|
|
1167
|
+
_state.label = 4;
|
|
1168
|
+
case 4:
|
|
1169
|
+
_iteratorNormalCompletion = true;
|
|
1170
|
+
return [
|
|
1171
|
+
3,
|
|
1172
|
+
2
|
|
1173
|
+
];
|
|
1174
|
+
case 5:
|
|
1175
|
+
return [
|
|
1176
|
+
3,
|
|
1177
|
+
8
|
|
1178
|
+
];
|
|
1179
|
+
case 6:
|
|
1180
|
+
err = _state.sent();
|
|
1181
|
+
_didIteratorError = true;
|
|
1182
|
+
_iteratorError = err;
|
|
1183
|
+
return [
|
|
1184
|
+
3,
|
|
1185
|
+
8
|
|
1186
|
+
];
|
|
1187
|
+
case 7:
|
|
1188
|
+
try {
|
|
1189
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1190
|
+
_iterator.return();
|
|
1191
|
+
}
|
|
1192
|
+
} finally{
|
|
1193
|
+
if (_didIteratorError) {
|
|
1194
|
+
throw _iteratorError;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
return [
|
|
1198
|
+
7
|
|
1199
|
+
];
|
|
1200
|
+
case 8:
|
|
1201
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
1202
|
+
_state.label = 9;
|
|
1203
|
+
case 9:
|
|
1204
|
+
_state.trys.push([
|
|
1205
|
+
9,
|
|
1206
|
+
14,
|
|
1207
|
+
15,
|
|
1208
|
+
16
|
|
1209
|
+
]);
|
|
1210
|
+
_iterator1 = _classPrivateFieldGet(this, _cache)[Symbol.iterator]();
|
|
1211
|
+
_state.label = 10;
|
|
1212
|
+
case 10:
|
|
1213
|
+
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
|
|
1214
|
+
3,
|
|
1215
|
+
13
|
|
1216
|
+
];
|
|
1217
|
+
item1 = _step1.value;
|
|
1218
|
+
_item1 = _slicedToArray(item1, 2), key1 = _item1[0], value1 = _item1[1];
|
|
1219
|
+
deleted1 = _classPrivateMethodGet(this, _deleteIfExpired, deleteIfExpired).call(this, key1, value1);
|
|
1220
|
+
if (!(deleted1 === false)) return [
|
|
1221
|
+
3,
|
|
1222
|
+
12
|
|
1223
|
+
];
|
|
1224
|
+
return [
|
|
1225
|
+
4,
|
|
1226
|
+
item1
|
|
1227
|
+
];
|
|
1228
|
+
case 11:
|
|
1229
|
+
_state.sent();
|
|
1230
|
+
_state.label = 12;
|
|
1231
|
+
case 12:
|
|
1232
|
+
_iteratorNormalCompletion1 = true;
|
|
1233
|
+
return [
|
|
1234
|
+
3,
|
|
1235
|
+
10
|
|
1236
|
+
];
|
|
1237
|
+
case 13:
|
|
1238
|
+
return [
|
|
1239
|
+
3,
|
|
1240
|
+
16
|
|
1241
|
+
];
|
|
1242
|
+
case 14:
|
|
1243
|
+
err = _state.sent();
|
|
1244
|
+
_didIteratorError1 = true;
|
|
1245
|
+
_iteratorError1 = err;
|
|
1246
|
+
return [
|
|
1247
|
+
3,
|
|
1248
|
+
16
|
|
1249
|
+
];
|
|
1250
|
+
case 15:
|
|
1251
|
+
try {
|
|
1252
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
1253
|
+
_iterator1.return();
|
|
1254
|
+
}
|
|
1255
|
+
} finally{
|
|
1256
|
+
if (_didIteratorError1) {
|
|
1257
|
+
throw _iteratorError1;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return [
|
|
1261
|
+
7
|
|
1262
|
+
];
|
|
1263
|
+
case 16:
|
|
1264
|
+
return [
|
|
1265
|
+
2
|
|
1266
|
+
];
|
|
1267
|
+
}
|
|
1268
|
+
});
|
|
1269
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common.js/quick-lru",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "quick-lru package exported as CommonJS modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "etienne-martin/common.js",
|
|
7
7
|
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">=18"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"
|
|
14
|
-
"test": "xo && ava && tsd"
|
|
13
|
+
"test": "xo && nyc ava && tsd"
|
|
15
14
|
},
|
|
16
15
|
"files": [
|
|
17
16
|
"index.js",
|
|
18
17
|
"index.d.ts"
|
|
19
18
|
],
|
|
20
19
|
"devDependencies": {
|
|
21
|
-
"ava": "^3.
|
|
20
|
+
"ava": "^5.3.1",
|
|
22
21
|
"nyc": "^15.1.0",
|
|
23
|
-
"tsd": "^0.
|
|
24
|
-
"xo": "^0.
|
|
22
|
+
"tsd": "^0.29.0",
|
|
23
|
+
"xo": "^0.56.0"
|
|
25
24
|
},
|
|
26
25
|
"nyc": {
|
|
27
26
|
"reporter": [
|
|
@@ -31,5 +30,6 @@
|
|
|
31
30
|
},
|
|
32
31
|
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
33
32
|
"dependencies": {},
|
|
33
|
+
"types": "./index.d.ts",
|
|
34
34
|
"main": "./index.js"
|
|
35
35
|
}
|
package/readme.md
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# quick-lru [](https://codecov.io/gh/sindresorhus/quick-lru/branch/main)
|
|
2
|
-
|
|
3
|
-
> Simple [“Least Recently Used” (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29)
|
|
4
|
-
|
|
5
|
-
Useful when you need to cache something and limit memory usage.
|
|
6
|
-
|
|
7
|
-
Inspired by the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm), but instead uses [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) to support keys of any type, not just strings, and values can be `undefined`.
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
$ npm install quick-lru
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
import QuickLRU from 'quick-lru';
|
|
19
|
-
|
|
20
|
-
const lru = new QuickLRU({maxSize: 1000});
|
|
21
|
-
|
|
22
|
-
lru.set('🦄', '🌈');
|
|
23
|
-
|
|
24
|
-
lru.has('🦄');
|
|
25
|
-
//=> true
|
|
26
|
-
|
|
27
|
-
lru.get('🦄');
|
|
28
|
-
//=> '🌈'
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## API
|
|
32
|
-
|
|
33
|
-
### new QuickLRU(options?)
|
|
34
|
-
|
|
35
|
-
Returns a new instance.
|
|
36
|
-
|
|
37
|
-
It's a [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) subclass.
|
|
38
|
-
|
|
39
|
-
### options
|
|
40
|
-
|
|
41
|
-
Type: `object`
|
|
42
|
-
|
|
43
|
-
#### maxSize
|
|
44
|
-
|
|
45
|
-
*Required*\
|
|
46
|
-
Type: `number`
|
|
47
|
-
|
|
48
|
-
The maximum number of items before evicting the least recently used items.
|
|
49
|
-
|
|
50
|
-
#### maxAge
|
|
51
|
-
|
|
52
|
-
Type: `number`\
|
|
53
|
-
Default: `Infinity`
|
|
54
|
-
|
|
55
|
-
The maximum number of milliseconds an item should remain in cache.
|
|
56
|
-
By default maxAge will be Infinity, which means that items will never expire.
|
|
57
|
-
|
|
58
|
-
Lazy expiration happens upon the next `write` or `read` call.
|
|
59
|
-
|
|
60
|
-
Individual expiration of an item can be specified by the `set(key, value, options)` method.
|
|
61
|
-
|
|
62
|
-
#### onEviction
|
|
63
|
-
|
|
64
|
-
*Optional*\
|
|
65
|
-
Type: `(key, value) => void`
|
|
66
|
-
|
|
67
|
-
Called right before an item is evicted from the cache.
|
|
68
|
-
|
|
69
|
-
Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
|
|
70
|
-
|
|
71
|
-
### Instance
|
|
72
|
-
|
|
73
|
-
The instance is an [`Iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) of `[key, value]` pairs so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
|
|
74
|
-
|
|
75
|
-
Both `key` and `value` can be of any type.
|
|
76
|
-
|
|
77
|
-
#### .set(key, value, options?)
|
|
78
|
-
|
|
79
|
-
Set an item. Returns the instance.
|
|
80
|
-
|
|
81
|
-
Individual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified on the constructor, otherwise the item will never expire.
|
|
82
|
-
|
|
83
|
-
#### .get(key)
|
|
84
|
-
|
|
85
|
-
Get an item.
|
|
86
|
-
|
|
87
|
-
#### .has(key)
|
|
88
|
-
|
|
89
|
-
Check if an item exists.
|
|
90
|
-
|
|
91
|
-
#### .peek(key)
|
|
92
|
-
|
|
93
|
-
Get an item without marking it as recently used.
|
|
94
|
-
|
|
95
|
-
#### .delete(key)
|
|
96
|
-
|
|
97
|
-
Delete an item.
|
|
98
|
-
|
|
99
|
-
Returns `true` if the item is removed or `false` if the item doesn't exist.
|
|
100
|
-
|
|
101
|
-
#### .clear()
|
|
102
|
-
|
|
103
|
-
Delete all items.
|
|
104
|
-
|
|
105
|
-
#### .resize(maxSize)
|
|
106
|
-
|
|
107
|
-
Update the `maxSize`, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
|
|
108
|
-
|
|
109
|
-
Useful for on-the-fly tuning of cache sizes in live systems.
|
|
110
|
-
|
|
111
|
-
#### .keys()
|
|
112
|
-
|
|
113
|
-
Iterable for all the keys.
|
|
114
|
-
|
|
115
|
-
#### .values()
|
|
116
|
-
|
|
117
|
-
Iterable for all the values.
|
|
118
|
-
|
|
119
|
-
#### .entriesAscending()
|
|
120
|
-
|
|
121
|
-
Iterable for all entries, starting with the oldest (ascending in recency).
|
|
122
|
-
|
|
123
|
-
#### .entriesDescending()
|
|
124
|
-
|
|
125
|
-
Iterable for all entries, starting with the newest (descending in recency).
|
|
126
|
-
|
|
127
|
-
#### .entries()
|
|
128
|
-
|
|
129
|
-
Iterable for all entries, starting with the newest (ascending in recency).
|
|
130
|
-
|
|
131
|
-
**This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.**
|
|
132
|
-
|
|
133
|
-
#### .forEach(callbackFunction, thisArgument)
|
|
134
|
-
|
|
135
|
-
Loop over entries calling the `callbackFunction` for each entry (ascending in recency).
|
|
136
|
-
|
|
137
|
-
**This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.**
|
|
138
|
-
|
|
139
|
-
#### .size
|
|
140
|
-
|
|
141
|
-
The stored item count.
|
|
142
|
-
|
|
143
|
-
## Related
|
|
144
|
-
|
|
145
|
-
- [yocto-queue](https://github.com/sindresorhus/yocto-queue) - Tiny queue data structure
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
<div align="center">
|
|
150
|
-
<b>
|
|
151
|
-
<a href="https://tidelift.com/subscription/pkg/npm-quick-lru?utm_source=npm-quick-lru&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
152
|
-
</b>
|
|
153
|
-
<br>
|
|
154
|
-
<sub>
|
|
155
|
-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
156
|
-
</sub>
|
|
157
|
-
</div>
|