cacheable 1.2.0 → 1.3.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/dist/index.cjs CHANGED
@@ -584,7 +584,7 @@ var Cacheable = class extends import_hookified.Hookified {
584
584
  }
585
585
  await this.hook("AFTER_GET" /* AFTER_GET */, { key, result });
586
586
  } catch (error) {
587
- await this.emit("error" /* ERROR */, error);
587
+ this.emit("error" /* ERROR */, error);
588
588
  }
589
589
  if (this.stats.enabled) {
590
590
  if (result) {
@@ -618,7 +618,7 @@ var Cacheable = class extends import_hookified.Hookified {
618
618
  }
619
619
  await this.hook("AFTER_GET_MANY" /* AFTER_GET_MANY */, { keys, result });
620
620
  } catch (error) {
621
- await this.emit("error" /* ERROR */, error);
621
+ this.emit("error" /* ERROR */, error);
622
622
  }
623
623
  if (this.stats.enabled) {
624
624
  for (const item of result) {
@@ -636,11 +636,12 @@ var Cacheable = class extends import_hookified.Hookified {
636
636
  let result = false;
637
637
  const finalTtl = ttl ?? this._ttl;
638
638
  try {
639
- await this.hook("BEFORE_SET" /* BEFORE_SET */, { key, value, finalTtl });
639
+ const item = { key, value, ttl: finalTtl };
640
+ await this.hook("BEFORE_SET" /* BEFORE_SET */, item);
640
641
  const promises = [];
641
- promises.push(this._primary.set(key, value, finalTtl));
642
+ promises.push(this._primary.set(item.key, item.value, item.ttl));
642
643
  if (this._secondary) {
643
- promises.push(this._secondary.set(key, value, finalTtl));
644
+ promises.push(this._secondary.set(item.key, item.value, item.ttl));
644
645
  }
645
646
  if (this._nonBlocking) {
646
647
  result = await Promise.race(promises);
@@ -648,9 +649,9 @@ var Cacheable = class extends import_hookified.Hookified {
648
649
  const results = await Promise.all(promises);
649
650
  result = results[0];
650
651
  }
651
- await this.hook("AFTER_SET" /* AFTER_SET */, { key, value, finalTtl });
652
+ await this.hook("AFTER_SET" /* AFTER_SET */, item);
652
653
  } catch (error) {
653
- await this.emit("error" /* ERROR */, error);
654
+ this.emit("error" /* ERROR */, error);
654
655
  }
655
656
  if (this.stats.enabled) {
656
657
  this.stats.incrementKSize(key);
@@ -674,7 +675,7 @@ var Cacheable = class extends import_hookified.Hookified {
674
675
  }
675
676
  await this.hook("AFTER_SET_MANY" /* AFTER_SET_MANY */, items);
676
677
  } catch (error) {
677
- await this.emit("error" /* ERROR */, error);
678
+ this.emit("error" /* ERROR */, error);
678
679
  }
679
680
  if (this.stats.enabled) {
680
681
  for (const item of items) {
package/dist/index.js CHANGED
@@ -556,7 +556,7 @@ var Cacheable = class extends Hookified {
556
556
  }
557
557
  await this.hook("AFTER_GET" /* AFTER_GET */, { key, result });
558
558
  } catch (error) {
559
- await this.emit("error" /* ERROR */, error);
559
+ this.emit("error" /* ERROR */, error);
560
560
  }
561
561
  if (this.stats.enabled) {
562
562
  if (result) {
@@ -590,7 +590,7 @@ var Cacheable = class extends Hookified {
590
590
  }
591
591
  await this.hook("AFTER_GET_MANY" /* AFTER_GET_MANY */, { keys, result });
592
592
  } catch (error) {
593
- await this.emit("error" /* ERROR */, error);
593
+ this.emit("error" /* ERROR */, error);
594
594
  }
595
595
  if (this.stats.enabled) {
596
596
  for (const item of result) {
@@ -608,11 +608,12 @@ var Cacheable = class extends Hookified {
608
608
  let result = false;
609
609
  const finalTtl = ttl ?? this._ttl;
610
610
  try {
611
- await this.hook("BEFORE_SET" /* BEFORE_SET */, { key, value, finalTtl });
611
+ const item = { key, value, ttl: finalTtl };
612
+ await this.hook("BEFORE_SET" /* BEFORE_SET */, item);
612
613
  const promises = [];
613
- promises.push(this._primary.set(key, value, finalTtl));
614
+ promises.push(this._primary.set(item.key, item.value, item.ttl));
614
615
  if (this._secondary) {
615
- promises.push(this._secondary.set(key, value, finalTtl));
616
+ promises.push(this._secondary.set(item.key, item.value, item.ttl));
616
617
  }
617
618
  if (this._nonBlocking) {
618
619
  result = await Promise.race(promises);
@@ -620,9 +621,9 @@ var Cacheable = class extends Hookified {
620
621
  const results = await Promise.all(promises);
621
622
  result = results[0];
622
623
  }
623
- await this.hook("AFTER_SET" /* AFTER_SET */, { key, value, finalTtl });
624
+ await this.hook("AFTER_SET" /* AFTER_SET */, item);
624
625
  } catch (error) {
625
- await this.emit("error" /* ERROR */, error);
626
+ this.emit("error" /* ERROR */, error);
626
627
  }
627
628
  if (this.stats.enabled) {
628
629
  this.stats.incrementKSize(key);
@@ -646,7 +647,7 @@ var Cacheable = class extends Hookified {
646
647
  }
647
648
  await this.hook("AFTER_SET_MANY" /* AFTER_SET_MANY */, items);
648
649
  } catch (error) {
649
- await this.emit("error" /* ERROR */, error);
650
+ this.emit("error" /* ERROR */, error);
650
651
  }
651
652
  if (this.stats.enabled) {
652
653
  for (const item of items) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cacheable",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Simple Caching Engine using Keyv",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,9 +28,35 @@
28
28
  "xo": "^0.59.3"
29
29
  },
30
30
  "dependencies": {
31
- "hookified": "^0.7.1",
32
- "keyv": "^5.0.1"
31
+ "hookified": "^1.1.0",
32
+ "keyv": "^5.0.3"
33
33
  },
34
+ "keywords": [
35
+ "cacheable",
36
+ "high performance",
37
+ "layer 1 caching",
38
+ "layer 2 caching",
39
+ "distributed caching",
40
+ "Keyv storage engine",
41
+ "memory caching",
42
+ "LRU cache",
43
+ "expiration",
44
+ "CacheableMemory",
45
+ "offline support",
46
+ "distributed sync",
47
+ "secondary store",
48
+ "primary store",
49
+ "non-blocking operations",
50
+ "cache statistics",
51
+ "layered caching",
52
+ "fault tolerant",
53
+ "scalable cache",
54
+ "in-memory cache",
55
+ "distributed cache",
56
+ "lruSize",
57
+ "lru",
58
+ "multi-tier cache"
59
+ ],
34
60
  "files": [
35
61
  "dist",
36
62
  "LICENSE"