keyv 5.5.2 → 5.5.3

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 CHANGED
@@ -44,6 +44,7 @@ There are a few existing modules similar to Keyv, however Keyv is different beca
44
44
  - [.deserialize](#deserialize)
45
45
  - [.compression](#compression)
46
46
  - [.useKeyPrefix](#usekeyprefix)
47
+ - [.stats](#stats)
47
48
  - [Keyv Instance](#keyv-instance)
48
49
  - [.set(key, value, [ttl])](#setkey-value-ttl)
49
50
  - [.setMany(entries)](#setmanyentries)
@@ -672,6 +673,55 @@ const keyv = new Keyv({ store: keyvRedis, throwOnErrors: true });
672
673
 
673
674
  What this does is it only throw on connection errors with the Redis client.
674
675
 
676
+ ## .stats
677
+ Type: `StatsManager`<br />
678
+ Default: `StatsManager` instance with `enabled: false`
679
+
680
+ The stats property provides access to statistics tracking for cache operations. When enabled via the `stats` option during initialization, it tracks hits, misses, sets, deletes, and errors.
681
+
682
+ ### Enabling Stats:
683
+ ```js
684
+ const keyv = new Keyv({ stats: true });
685
+ console.log(keyv.stats.enabled); // true
686
+ ```
687
+
688
+ ### Available Statistics:
689
+ - `hits`: Number of successful cache retrievals
690
+ - `misses`: Number of failed cache retrievals
691
+ - `sets`: Number of set operations
692
+ - `deletes`: Number of delete operations
693
+ - `errors`: Number of errors encountered
694
+
695
+ ### Accessing Stats:
696
+ ```js
697
+ const keyv = new Keyv({ stats: true });
698
+
699
+ await keyv.set('foo', 'bar');
700
+ await keyv.get('foo'); // cache hit
701
+ await keyv.get('nonexistent'); // cache miss
702
+ await keyv.delete('foo');
703
+
704
+ console.log(keyv.stats.hits); // 1
705
+ console.log(keyv.stats.misses); // 1
706
+ console.log(keyv.stats.sets); // 1
707
+ console.log(keyv.stats.deletes); // 1
708
+ ```
709
+
710
+ ### Resetting Stats:
711
+ ```js
712
+ keyv.stats.reset();
713
+ console.log(keyv.stats.hits); // 0
714
+ ```
715
+
716
+ ### Manual Control:
717
+ You can also manually enable/disable stats tracking at runtime:
718
+ ```js
719
+ const keyv = new Keyv({ stats: false });
720
+ keyv.stats.enabled = true; // Enable stats tracking
721
+ // ... perform operations ...
722
+ keyv.stats.enabled = false; // Disable stats tracking
723
+ ```
724
+
675
725
  # How to Contribute
676
726
 
677
727
  We welcome contributions to Keyv! 🎉 Here are some guides to get you started with contributing:
package/dist/index.cjs CHANGED
@@ -776,7 +776,8 @@ var Keyv = class extends event_manager_default {
776
776
  }
777
777
  const formattedValue = { value, expires };
778
778
  const serializedValue = await this.serializeData(formattedValue);
779
- return { key, value: serializedValue, ttl };
779
+ const keyPrefixed = this._getKeyPrefix(key);
780
+ return { key: keyPrefixed, value: serializedValue, ttl };
780
781
  })
781
782
  );
782
783
  results = await this._store.setMany(serializedEntries);
package/dist/index.js CHANGED
@@ -750,7 +750,8 @@ var Keyv = class extends event_manager_default {
750
750
  }
751
751
  const formattedValue = { value, expires };
752
752
  const serializedValue = await this.serializeData(formattedValue);
753
- return { key, value: serializedValue, ttl };
753
+ const keyPrefixed = this._getKeyPrefix(key);
754
+ return { key: keyPrefixed, value: serializedValue, ttl };
754
755
  })
755
756
  );
756
757
  results = await this._store.setMany(serializedEntries);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyv",
3
- "version": "5.5.2",
3
+ "version": "5.5.3",
4
4
  "description": "Simple key-value storage with support for multiple backends",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -54,12 +54,12 @@
54
54
  "timekeeper": "^2.3.1",
55
55
  "tsd": "^0.33.0",
56
56
  "vitest": "^3.2.4",
57
- "@keyv/compress-brotli": "^2.0.5",
58
- "@keyv/compress-lz4": "^1.0.1",
59
57
  "@keyv/mongo": "^3.0.3",
60
- "@keyv/memcache": "^2.0.2",
61
58
  "@keyv/compress-gzip": "^2.0.3",
59
+ "@keyv/compress-lz4": "^1.0.1",
60
+ "@keyv/memcache": "^2.0.2",
62
61
  "@keyv/sqlite": "^4.0.5",
62
+ "@keyv/compress-brotli": "^2.0.5",
63
63
  "@keyv/test-suite": "^2.1.1"
64
64
  },
65
65
  "tsd": {