keyv 5.5.1 → 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 +50 -0
- package/dist/index.cjs +3 -2
- package/dist/index.js +3 -2
- package/package.json +7 -5
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
|
-
|
|
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);
|
|
@@ -909,7 +910,7 @@ var Keyv = class extends event_manager_default {
|
|
|
909
910
|
return store.hasMany(keyPrefixed);
|
|
910
911
|
}
|
|
911
912
|
const results = [];
|
|
912
|
-
for (const key of
|
|
913
|
+
for (const key of keys) {
|
|
913
914
|
results.push(await this.has(key));
|
|
914
915
|
}
|
|
915
916
|
return results;
|
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
|
-
|
|
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);
|
|
@@ -883,7 +884,7 @@ var Keyv = class extends event_manager_default {
|
|
|
883
884
|
return store.hasMany(keyPrefixed);
|
|
884
885
|
}
|
|
885
886
|
const results = [];
|
|
886
|
-
for (const key of
|
|
887
|
+
for (const key of keys) {
|
|
887
888
|
results.push(await this.has(key));
|
|
888
889
|
}
|
|
889
890
|
return results;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "5.5.
|
|
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",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"tsd": "^0.33.0",
|
|
56
56
|
"vitest": "^3.2.4",
|
|
57
57
|
"@keyv/mongo": "^3.0.3",
|
|
58
|
+
"@keyv/compress-gzip": "^2.0.3",
|
|
58
59
|
"@keyv/compress-lz4": "^1.0.1",
|
|
59
60
|
"@keyv/memcache": "^2.0.2",
|
|
60
61
|
"@keyv/sqlite": "^4.0.5",
|
|
61
|
-
"@keyv/test-suite": "^2.1.1",
|
|
62
62
|
"@keyv/compress-brotli": "^2.0.5",
|
|
63
|
-
"@keyv/
|
|
63
|
+
"@keyv/test-suite": "^2.1.1"
|
|
64
64
|
},
|
|
65
65
|
"tsd": {
|
|
66
66
|
"directory": "test"
|
|
@@ -71,8 +71,10 @@
|
|
|
71
71
|
],
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
74
|
-
"
|
|
75
|
-
"
|
|
74
|
+
"lint": "biome check --write --error-on-warnings",
|
|
75
|
+
"lint:ci": "biome check --error-on-warnings",
|
|
76
|
+
"test": "pnpm lint && vitest run --coverage",
|
|
77
|
+
"test:ci": "pnpm lint:ci && vitest --run --sequence.setupFiles=list --coverage",
|
|
76
78
|
"clean": "rimraf ./node_modules ./coverage ./test/testdb.sqlite ./dist"
|
|
77
79
|
}
|
|
78
80
|
}
|