@scayle/storefront-core 7.28.2 → 7.29.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/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.UnstorageCache = void 0;
|
|
7
|
-
var _compression = require("../../utils/compression.cjs");
|
|
8
7
|
class UnstorageCache {
|
|
9
8
|
storage;
|
|
10
9
|
prefix;
|
|
@@ -17,7 +16,7 @@ class UnstorageCache {
|
|
|
17
16
|
if (value === null) {
|
|
18
17
|
return null;
|
|
19
18
|
}
|
|
20
|
-
return
|
|
19
|
+
return value;
|
|
21
20
|
}
|
|
22
21
|
async has(key) {
|
|
23
22
|
return await this.storage.hasItem(this.getKey(key));
|
|
@@ -38,8 +37,7 @@ class UnstorageCache {
|
|
|
38
37
|
await Promise.all(keys.map(k => this.storage.removeItem(k)));
|
|
39
38
|
}
|
|
40
39
|
async set(key, value, ttl, tags = []) {
|
|
41
|
-
|
|
42
|
-
await this.storage.setItem(this.getKey(key), _value, {
|
|
40
|
+
await this.storage.setItem(this.getKey(key), value, {
|
|
43
41
|
ttl
|
|
44
42
|
});
|
|
45
43
|
await Promise.all(tags.map(tag => this.addKeyToTag(tag, this.getKey(key))));
|
|
@@ -53,26 +51,5 @@ class UnstorageCache {
|
|
|
53
51
|
getKey(key) {
|
|
54
52
|
return [this.prefix, key].join(":");
|
|
55
53
|
}
|
|
56
|
-
/**
|
|
57
|
-
* First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
|
|
58
|
-
* @param value String to be deserialized and decompressed
|
|
59
|
-
*/
|
|
60
|
-
async deserialize(value) {
|
|
61
|
-
try {
|
|
62
|
-
const data = await (0, _compression.decompress)(value);
|
|
63
|
-
return JSON.parse(data);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.warn("UnstorageCache: Unable to decompress data", error);
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
|
|
71
|
-
* @param value String to be deserialized and decompressed
|
|
72
|
-
*/
|
|
73
|
-
async serialize(value) {
|
|
74
|
-
const data = JSON.stringify(value);
|
|
75
|
-
return await (0, _compression.compress)(data);
|
|
76
|
-
}
|
|
77
54
|
}
|
|
78
55
|
exports.UnstorageCache = UnstorageCache;
|
|
@@ -13,14 +13,4 @@ export declare class UnstorageCache implements CacheInterface {
|
|
|
13
13
|
set(key: string, value: any, ttl: number, tags?: string[]): Promise<void>;
|
|
14
14
|
private addKeyToTag;
|
|
15
15
|
private getKey;
|
|
16
|
-
/**
|
|
17
|
-
* First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
|
|
18
|
-
* @param value String to be deserialized and decompressed
|
|
19
|
-
*/
|
|
20
|
-
private deserialize;
|
|
21
|
-
/**
|
|
22
|
-
* First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
|
|
23
|
-
* @param value String to be deserialized and decompressed
|
|
24
|
-
*/
|
|
25
|
-
private serialize;
|
|
26
16
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { compress, decompress } from "../../utils/compression.mjs";
|
|
2
1
|
export class UnstorageCache {
|
|
3
2
|
storage;
|
|
4
3
|
prefix;
|
|
@@ -11,7 +10,7 @@ export class UnstorageCache {
|
|
|
11
10
|
if (value === null) {
|
|
12
11
|
return null;
|
|
13
12
|
}
|
|
14
|
-
return
|
|
13
|
+
return value;
|
|
15
14
|
}
|
|
16
15
|
async has(key) {
|
|
17
16
|
return await this.storage.hasItem(this.getKey(key));
|
|
@@ -32,8 +31,7 @@ export class UnstorageCache {
|
|
|
32
31
|
await Promise.all(keys.map((k) => this.storage.removeItem(k)));
|
|
33
32
|
}
|
|
34
33
|
async set(key, value, ttl, tags = []) {
|
|
35
|
-
|
|
36
|
-
await this.storage.setItem(this.getKey(key), _value, { ttl });
|
|
34
|
+
await this.storage.setItem(this.getKey(key), value, { ttl });
|
|
37
35
|
await Promise.all(
|
|
38
36
|
tags.map((tag) => this.addKeyToTag(tag, this.getKey(key)))
|
|
39
37
|
);
|
|
@@ -47,25 +45,4 @@ export class UnstorageCache {
|
|
|
47
45
|
getKey(key) {
|
|
48
46
|
return [this.prefix, key].join(":");
|
|
49
47
|
}
|
|
50
|
-
/**
|
|
51
|
-
* First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
|
|
52
|
-
* @param value String to be deserialized and decompressed
|
|
53
|
-
*/
|
|
54
|
-
async deserialize(value) {
|
|
55
|
-
try {
|
|
56
|
-
const data = await decompress(value);
|
|
57
|
-
return JSON.parse(data);
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.warn("UnstorageCache: Unable to decompress data", error);
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
|
|
65
|
-
* @param value String to be deserialized and decompressed
|
|
66
|
-
*/
|
|
67
|
-
async serialize(value) {
|
|
68
|
-
const data = JSON.stringify(value);
|
|
69
|
-
return await compress(data);
|
|
70
|
-
}
|
|
71
48
|
}
|