lib0 0.2.45 → 0.2.46
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 -0
- package/cache.d.ts +1 -0
- package/cache.d.ts.map +1 -1
- package/cache.js +19 -9
- package/cache.test.d.ts.map +1 -1
- package/dist/cache.cjs +20 -9
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.ts +1 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.test.d.ts.map +1 -1
- package/dist/test.cjs +33 -11
- package/dist/test.cjs.map +1 -1
- package/dist/test.js +33 -11
- package/dist/test.js.map +1 -1
- package/package.json +1 -1
package/dist/test.js
CHANGED
|
@@ -7369,13 +7369,9 @@
|
|
|
7369
7369
|
* @return {Entry<K, V> | undefined}
|
|
7370
7370
|
*/
|
|
7371
7371
|
const getNode = (cache, key) => {
|
|
7372
|
-
|
|
7373
|
-
const q = cache._q;
|
|
7372
|
+
removeStale(cache);
|
|
7374
7373
|
const n = cache._map.get(key);
|
|
7375
7374
|
if (n) {
|
|
7376
|
-
removeNode(q, n);
|
|
7377
|
-
pushEnd(q, n);
|
|
7378
|
-
n.created = now;
|
|
7379
7375
|
return n
|
|
7380
7376
|
}
|
|
7381
7377
|
};
|
|
@@ -7392,6 +7388,23 @@
|
|
|
7392
7388
|
return n && !(n.val instanceof Promise) ? n.val : undefined
|
|
7393
7389
|
};
|
|
7394
7390
|
|
|
7391
|
+
/**
|
|
7392
|
+
* @template K, V
|
|
7393
|
+
*
|
|
7394
|
+
* @param {Cache<K, V>} cache
|
|
7395
|
+
* @param {K} key
|
|
7396
|
+
*/
|
|
7397
|
+
const refreshTimeout = (cache, key) => {
|
|
7398
|
+
const now = getUnixTime();
|
|
7399
|
+
const q = cache._q;
|
|
7400
|
+
const n = cache._map.get(key);
|
|
7401
|
+
if (n) {
|
|
7402
|
+
removeNode(q, n);
|
|
7403
|
+
pushEnd(q, n);
|
|
7404
|
+
n.created = now;
|
|
7405
|
+
}
|
|
7406
|
+
};
|
|
7407
|
+
|
|
7395
7408
|
/**
|
|
7396
7409
|
* Works well in conjunktion with setIfUndefined which has an async init function.
|
|
7397
7410
|
* Using getAsync & setIfUndefined ensures that the init function is only called once.
|
|
@@ -7432,13 +7445,10 @@
|
|
|
7432
7445
|
* @return {Promise<V> | V}
|
|
7433
7446
|
*/
|
|
7434
7447
|
const setIfUndefined = (cache, key, init, removeNull = false) => {
|
|
7435
|
-
|
|
7448
|
+
removeStale(cache);
|
|
7436
7449
|
const q = cache._q;
|
|
7437
7450
|
const n = cache._map.get(key);
|
|
7438
7451
|
if (n) {
|
|
7439
|
-
removeNode(q, n);
|
|
7440
|
-
pushEnd(q, n);
|
|
7441
|
-
n.created = now;
|
|
7442
7452
|
return n.val
|
|
7443
7453
|
} else {
|
|
7444
7454
|
const p = init();
|
|
@@ -7495,11 +7505,13 @@
|
|
|
7495
7505
|
|
|
7496
7506
|
// write new values and check later if the creation-timestamp was updated
|
|
7497
7507
|
set(c, 'a', '11');
|
|
7498
|
-
|
|
7508
|
+
set(c, 'b', '22');
|
|
7499
7509
|
|
|
7500
7510
|
await wait(5); // keys should be updated and not timed out. Hence the creation time should be updated
|
|
7501
7511
|
assert(get(c, 'a') === '11');
|
|
7502
|
-
assert(get(c, 'b') === '
|
|
7512
|
+
assert(get(c, 'b') === '22');
|
|
7513
|
+
set(c, 'a', '11');
|
|
7514
|
+
set(c, 'b', '22');
|
|
7503
7515
|
// timestamps should be updated
|
|
7504
7516
|
assert(aTimestamp1 !== m.get('a').created);
|
|
7505
7517
|
assert(bTimestamp1 !== m.get('b').created);
|
|
@@ -7528,6 +7540,16 @@
|
|
|
7528
7540
|
const yp = setIfUndefined(c, 'a', () => resolveWith(null), true);
|
|
7529
7541
|
assert(await yp === null);
|
|
7530
7542
|
assert(get(c, 'a') === undefined);
|
|
7543
|
+
|
|
7544
|
+
// check manual updating of timeout
|
|
7545
|
+
set(c, 'a', '3');
|
|
7546
|
+
const ts1 = m.get('a').created;
|
|
7547
|
+
await wait(30);
|
|
7548
|
+
refreshTimeout(c, 'a');
|
|
7549
|
+
const ts2 = m.get('a').created;
|
|
7550
|
+
assert(ts1 !== ts2);
|
|
7551
|
+
refreshTimeout(c, 'x'); // for full test coverage
|
|
7552
|
+
assert(m.get('x') == null);
|
|
7531
7553
|
};
|
|
7532
7554
|
|
|
7533
7555
|
var cache = /*#__PURE__*/Object.freeze({
|