cacheable 2.3.3 → 2.3.5
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 +4 -3
- package/dist/index.cjs +17 -6
- package/dist/index.js +17 -6
- package/package.json +6 -10
package/README.md
CHANGED
|
@@ -171,8 +171,9 @@ When `Getting Data` if the value does not exist in the primary store it will try
|
|
|
171
171
|
|
|
172
172
|
```javascript
|
|
173
173
|
import { Cacheable } from 'cacheable';
|
|
174
|
+
import {Keyv} from 'keyv';
|
|
174
175
|
import KeyvRedis from '@keyv/redis';
|
|
175
|
-
const secondary = new KeyvRedis('redis://user:pass@localhost:6379',
|
|
176
|
+
const secondary = new Keyv({ store: new KeyvRedis('redis://user:pass@localhost:6379'), ttl: 1000 });
|
|
176
177
|
const cache = new Cacheable({secondary, ttl: 100});
|
|
177
178
|
|
|
178
179
|
await cache.set('key', 'value'); // sets the value in the primary store with a ttl of 100 ms and secondary store with a ttl of 1000 ms
|
|
@@ -189,10 +190,10 @@ import { Cacheable } from 'cacheable';
|
|
|
189
190
|
import {Keyv} from 'keyv';
|
|
190
191
|
import KeyvRedis from '@keyv/redis';
|
|
191
192
|
const primary = new Keyv({ ttl: 200 });
|
|
192
|
-
const secondary = new KeyvRedis('redis://user:pass@localhost:6379',
|
|
193
|
+
const secondary = new Keyv({ store: new KeyvRedis('redis://user:pass@localhost:6379'), ttl: 1000 });
|
|
193
194
|
const cache = new Cacheable({primary, secondary});
|
|
194
195
|
|
|
195
|
-
await cache.set('key', 'value'); // sets the value in the primary store with a ttl of
|
|
196
|
+
await cache.set('key', 'value'); // sets the value in the primary store with a ttl of 200 ms and secondary store with a ttl of 1000 ms
|
|
196
197
|
|
|
197
198
|
await sleep(200); // wait for .2 seconds
|
|
198
199
|
|
package/dist/index.cjs
CHANGED
|
@@ -119,8 +119,8 @@ var CacheableSync = class extends import_hookified.Hookified {
|
|
|
119
119
|
if (this._storage && this._cacheId) {
|
|
120
120
|
const oldSetEvent = this.getPrefixedEvent("cache:set" /* SET */);
|
|
121
121
|
const oldDeleteEvent = this.getPrefixedEvent("cache:delete" /* DELETE */);
|
|
122
|
-
void this._qified.
|
|
123
|
-
void this._qified.
|
|
122
|
+
void this._qified.unsubscribeMessage(oldSetEvent);
|
|
123
|
+
void this._qified.unsubscribeMessage(oldDeleteEvent);
|
|
124
124
|
}
|
|
125
125
|
this._namespace = namespace;
|
|
126
126
|
if (this._storage && this._cacheId) {
|
|
@@ -605,14 +605,21 @@ var Cacheable = class extends import_hookified2.Hookified {
|
|
|
605
605
|
*/
|
|
606
606
|
async set(key, value, ttl) {
|
|
607
607
|
let result = false;
|
|
608
|
-
const
|
|
608
|
+
const explicitTtl = (0, import_utils.shorthandToMilliseconds)(ttl);
|
|
609
609
|
try {
|
|
610
|
-
const
|
|
610
|
+
const primaryTtl = (0, import_utils.getCascadingTtl)(
|
|
611
|
+
this._ttl,
|
|
612
|
+
this._primary.ttl,
|
|
613
|
+
explicitTtl
|
|
614
|
+
);
|
|
615
|
+
const item = { key, value, ttl: primaryTtl };
|
|
611
616
|
await this.hook("BEFORE_SET" /* BEFORE_SET */, item);
|
|
617
|
+
const hookOverridden = item.ttl !== primaryTtl;
|
|
612
618
|
const promises = [];
|
|
613
619
|
promises.push(this._primary.set(item.key, item.value, item.ttl));
|
|
614
620
|
if (this._secondary) {
|
|
615
|
-
|
|
621
|
+
const secondaryTtl = hookOverridden ? item.ttl : (0, import_utils.getCascadingTtl)(this._ttl, this._secondary.ttl, explicitTtl);
|
|
622
|
+
promises.push(this._secondary.set(item.key, item.value, secondaryTtl));
|
|
616
623
|
}
|
|
617
624
|
if (this._nonBlocking) {
|
|
618
625
|
result = await Promise.race(promises);
|
|
@@ -948,7 +955,11 @@ var Cacheable = class extends import_hookified2.Hookified {
|
|
|
948
955
|
async setManyKeyv(keyv, items) {
|
|
949
956
|
const entries = [];
|
|
950
957
|
for (const item of items) {
|
|
951
|
-
const finalTtl = (0, import_utils.
|
|
958
|
+
const finalTtl = (0, import_utils.getCascadingTtl)(
|
|
959
|
+
this._ttl,
|
|
960
|
+
keyv.ttl,
|
|
961
|
+
(0, import_utils.shorthandToMilliseconds)(item.ttl)
|
|
962
|
+
);
|
|
952
963
|
entries.push({ key: item.key, value: item.value, ttl: finalTtl });
|
|
953
964
|
}
|
|
954
965
|
await keyv.setMany(entries);
|
package/dist/index.js
CHANGED
|
@@ -89,8 +89,8 @@ var CacheableSync = class extends Hookified {
|
|
|
89
89
|
if (this._storage && this._cacheId) {
|
|
90
90
|
const oldSetEvent = this.getPrefixedEvent("cache:set" /* SET */);
|
|
91
91
|
const oldDeleteEvent = this.getPrefixedEvent("cache:delete" /* DELETE */);
|
|
92
|
-
void this._qified.
|
|
93
|
-
void this._qified.
|
|
92
|
+
void this._qified.unsubscribeMessage(oldSetEvent);
|
|
93
|
+
void this._qified.unsubscribeMessage(oldDeleteEvent);
|
|
94
94
|
}
|
|
95
95
|
this._namespace = namespace;
|
|
96
96
|
if (this._storage && this._cacheId) {
|
|
@@ -590,14 +590,21 @@ var Cacheable = class extends Hookified2 {
|
|
|
590
590
|
*/
|
|
591
591
|
async set(key, value, ttl) {
|
|
592
592
|
let result = false;
|
|
593
|
-
const
|
|
593
|
+
const explicitTtl = shorthandToMilliseconds(ttl);
|
|
594
594
|
try {
|
|
595
|
-
const
|
|
595
|
+
const primaryTtl = getCascadingTtl(
|
|
596
|
+
this._ttl,
|
|
597
|
+
this._primary.ttl,
|
|
598
|
+
explicitTtl
|
|
599
|
+
);
|
|
600
|
+
const item = { key, value, ttl: primaryTtl };
|
|
596
601
|
await this.hook("BEFORE_SET" /* BEFORE_SET */, item);
|
|
602
|
+
const hookOverridden = item.ttl !== primaryTtl;
|
|
597
603
|
const promises = [];
|
|
598
604
|
promises.push(this._primary.set(item.key, item.value, item.ttl));
|
|
599
605
|
if (this._secondary) {
|
|
600
|
-
|
|
606
|
+
const secondaryTtl = hookOverridden ? item.ttl : getCascadingTtl(this._ttl, this._secondary.ttl, explicitTtl);
|
|
607
|
+
promises.push(this._secondary.set(item.key, item.value, secondaryTtl));
|
|
601
608
|
}
|
|
602
609
|
if (this._nonBlocking) {
|
|
603
610
|
result = await Promise.race(promises);
|
|
@@ -933,7 +940,11 @@ var Cacheable = class extends Hookified2 {
|
|
|
933
940
|
async setManyKeyv(keyv, items) {
|
|
934
941
|
const entries = [];
|
|
935
942
|
for (const item of items) {
|
|
936
|
-
const finalTtl =
|
|
943
|
+
const finalTtl = getCascadingTtl(
|
|
944
|
+
this._ttl,
|
|
945
|
+
keyv.ttl,
|
|
946
|
+
shorthandToMilliseconds(item.ttl)
|
|
947
|
+
);
|
|
937
948
|
entries.push({ key: item.key, value: item.value, ttl: finalTtl });
|
|
938
949
|
}
|
|
939
950
|
await keyv.setMany(entries);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cacheable",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.5",
|
|
4
4
|
"description": "High Performance Layer 1 / Layer 2 Caching with Keyv Storage",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,22 +27,19 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"private": false,
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@keyv/redis": "^5.1.5",
|
|
30
|
+
"@keyv/redis": "^5.1.6",
|
|
32
31
|
"@keyv/valkey": "^1.0.11",
|
|
33
|
-
"@qified/redis": "^0.
|
|
34
|
-
"
|
|
35
|
-
"lru-cache": "^11.2.4",
|
|
36
|
-
"rimraf": "^6.1.2",
|
|
32
|
+
"@qified/redis": "^0.10.1",
|
|
33
|
+
"lru-cache": "^11.3.6",
|
|
37
34
|
"tsup": "^8.5.1",
|
|
38
35
|
"typescript": "^5.9.3"
|
|
39
36
|
},
|
|
40
37
|
"dependencies": {
|
|
41
38
|
"hookified": "^1.15.0",
|
|
42
39
|
"keyv": "^5.6.0",
|
|
43
|
-
"qified": "^0.
|
|
40
|
+
"qified": "^0.10.1",
|
|
44
41
|
"@cacheable/memory": "^2.0.8",
|
|
45
|
-
"@cacheable/utils": "^2.4.
|
|
42
|
+
"@cacheable/utils": "^2.4.1"
|
|
46
43
|
},
|
|
47
44
|
"keywords": [
|
|
48
45
|
"cacheable",
|
|
@@ -76,7 +73,6 @@
|
|
|
76
73
|
],
|
|
77
74
|
"scripts": {
|
|
78
75
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
79
|
-
"prepublish": "pnpm build",
|
|
80
76
|
"lint": "biome check --write --error-on-warnings",
|
|
81
77
|
"test": "pnpm lint && vitest run --coverage",
|
|
82
78
|
"test:ci": "biome check --error-on-warnings && vitest run --coverage",
|