@adviser/cement 0.3.15 → 0.3.16

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/index.cjs CHANGED
@@ -53,6 +53,7 @@ __export(index_exports, {
53
53
  Keyed: () => Keyed,
54
54
  KeyedResolvOnce: () => KeyedResolvOnce,
55
55
  KeyedResolvSeq: () => KeyedResolvSeq,
56
+ LRUCache: () => LRUCache,
56
57
  Level: () => Level,
57
58
  LevelHandlerImpl: () => LevelHandlerImpl,
58
59
  LevelHandlerSingleton: () => LevelHandlerSingleton,
@@ -3292,6 +3293,57 @@ function JSONEnDecoderSingleton(txtEnde) {
3292
3293
  return jsonEnDecoder;
3293
3294
  }
3294
3295
 
3296
+ // src/lru-cache.ts
3297
+ var LRUCache = class {
3298
+ constructor(c = {}) {
3299
+ this.cache = /* @__PURE__ */ new Map();
3300
+ this.param = {
3301
+ maxEntries: c.maxEntries || 100,
3302
+ maxAge: c.maxAge || 0
3303
+ };
3304
+ }
3305
+ touch(key) {
3306
+ const value = this.cache.get(key);
3307
+ this.cache.delete(key);
3308
+ this.cache.set(key, value);
3309
+ return value;
3310
+ }
3311
+ get size() {
3312
+ return this.cache.size;
3313
+ }
3314
+ async getPut(key, createFN) {
3315
+ const val = this.get(key);
3316
+ if (val) {
3317
+ return val;
3318
+ } else {
3319
+ const val2 = await createFN(key);
3320
+ this.put(key, val2);
3321
+ return val2;
3322
+ }
3323
+ }
3324
+ get(key) {
3325
+ if (this.cache.has(key)) {
3326
+ return this.touch(key);
3327
+ }
3328
+ return this.cache.get(key);
3329
+ }
3330
+ put(key, value) {
3331
+ this.cache.delete(key);
3332
+ if (this.cache.size >= this.param.maxEntries) {
3333
+ this.cache.delete(this.cache.keys().next().value);
3334
+ this.cache.set(key, value);
3335
+ } else {
3336
+ this.cache.set(key, value);
3337
+ }
3338
+ }
3339
+ // getLeastRecent(): K {
3340
+ // return Array.from(this.cache)[0];
3341
+ // }
3342
+ // getMostRecent(): K {
3343
+ // return Array.from(this.cache)[this.cache.size - 1];
3344
+ // }
3345
+ };
3346
+
3295
3347
  // src/utils/index.ts
3296
3348
  var utils_exports = {};
3297
3349
  __export(utils_exports, {
@@ -3545,6 +3597,7 @@ function UInt8ArrayEqual(a, b) {
3545
3597
  Keyed,
3546
3598
  KeyedResolvOnce,
3547
3599
  KeyedResolvSeq,
3600
+ LRUCache,
3548
3601
  Level,
3549
3602
  LevelHandlerImpl,
3550
3603
  LevelHandlerSingleton,