@b9g/cache-redis 0.1.0 → 0.1.2
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/package.json +3 -3
- package/src/index.cjs +7 -0
- package/src/index.d.ts +8 -0
- package/src/index.js +6 -0
- package/src/redis-cache.cjs +27 -27
- package/src/redis-cache.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/cache-redis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Redis cache adapter for Shovel cache system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cache",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"redis": "^4.6.10"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@b9g/libuild": "^0.1.
|
|
23
|
+
"@b9g/libuild": "^0.1.11"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@b9g/cache": "
|
|
26
|
+
"@b9g/cache": "^0.1.3"
|
|
27
27
|
},
|
|
28
28
|
"type": "module",
|
|
29
29
|
"types": "src/index.d.ts",
|
package/src/index.cjs
CHANGED
|
@@ -20,13 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var src_exports = {};
|
|
21
21
|
__export(src_exports, {
|
|
22
22
|
RedisCache: () => import_redis_cache.RedisCache,
|
|
23
|
+
createCache: () => createCache,
|
|
23
24
|
createRedisFactory: () => import_factory.createRedisFactory
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(src_exports);
|
|
26
27
|
var import_redis_cache = require("./redis-cache.cjs");
|
|
27
28
|
var import_factory = require("./factory.cjs");
|
|
29
|
+
var import_redis_cache2 = require("./redis-cache.cjs");
|
|
30
|
+
function createCache(config = {}) {
|
|
31
|
+
const name = config.name || "default";
|
|
32
|
+
return new import_redis_cache2.RedisCache(name, config);
|
|
33
|
+
}
|
|
28
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
35
|
0 && (module.exports = {
|
|
30
36
|
RedisCache,
|
|
37
|
+
createCache,
|
|
31
38
|
createRedisFactory
|
|
32
39
|
});
|
package/src/index.d.ts
CHANGED
|
@@ -5,3 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { RedisCache, type RedisCacheOptions } from "./redis-cache.js";
|
|
7
7
|
export { createRedisFactory } from "./factory.js";
|
|
8
|
+
import { RedisCache, type RedisCacheOptions } from "./redis-cache.js";
|
|
9
|
+
/**
|
|
10
|
+
* Platform adapter factory function
|
|
11
|
+
* Creates a RedisCache instance with the given configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function createCache(config?: RedisCacheOptions & {
|
|
14
|
+
name?: string;
|
|
15
|
+
}): RedisCache;
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
// src/index.ts
|
|
3
3
|
import { RedisCache } from "./redis-cache.js";
|
|
4
4
|
import { createRedisFactory } from "./factory.js";
|
|
5
|
+
import { RedisCache as RedisCache2 } from "./redis-cache.js";
|
|
6
|
+
function createCache(config = {}) {
|
|
7
|
+
const name = config.name || "default";
|
|
8
|
+
return new RedisCache2(name, config);
|
|
9
|
+
}
|
|
5
10
|
export {
|
|
6
11
|
RedisCache,
|
|
12
|
+
createCache,
|
|
7
13
|
createRedisFactory
|
|
8
14
|
};
|
package/src/redis-cache.cjs
CHANGED
|
@@ -8703,23 +8703,23 @@ var require_yallist = __commonJS({
|
|
|
8703
8703
|
Yallist.Node = Node;
|
|
8704
8704
|
Yallist.create = Yallist;
|
|
8705
8705
|
function Yallist(list) {
|
|
8706
|
-
var
|
|
8707
|
-
if (!(
|
|
8708
|
-
|
|
8706
|
+
var self2 = this;
|
|
8707
|
+
if (!(self2 instanceof Yallist)) {
|
|
8708
|
+
self2 = new Yallist();
|
|
8709
8709
|
}
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8710
|
+
self2.tail = null;
|
|
8711
|
+
self2.head = null;
|
|
8712
|
+
self2.length = 0;
|
|
8713
8713
|
if (list && typeof list.forEach === "function") {
|
|
8714
8714
|
list.forEach(function(item) {
|
|
8715
|
-
|
|
8715
|
+
self2.push(item);
|
|
8716
8716
|
});
|
|
8717
8717
|
} else if (arguments.length > 0) {
|
|
8718
8718
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
8719
|
-
|
|
8719
|
+
self2.push(arguments[i]);
|
|
8720
8720
|
}
|
|
8721
8721
|
}
|
|
8722
|
-
return
|
|
8722
|
+
return self2;
|
|
8723
8723
|
}
|
|
8724
8724
|
Yallist.prototype.removeNode = function(node) {
|
|
8725
8725
|
if (node.list !== this) {
|
|
@@ -9013,30 +9013,30 @@ var require_yallist = __commonJS({
|
|
|
9013
9013
|
this.tail = head;
|
|
9014
9014
|
return this;
|
|
9015
9015
|
};
|
|
9016
|
-
function insert(
|
|
9017
|
-
var inserted = node ===
|
|
9016
|
+
function insert(self2, node, value) {
|
|
9017
|
+
var inserted = node === self2.head ? new Node(value, null, node, self2) : new Node(value, node, node.next, self2);
|
|
9018
9018
|
if (inserted.next === null) {
|
|
9019
|
-
|
|
9019
|
+
self2.tail = inserted;
|
|
9020
9020
|
}
|
|
9021
9021
|
if (inserted.prev === null) {
|
|
9022
|
-
|
|
9022
|
+
self2.head = inserted;
|
|
9023
9023
|
}
|
|
9024
|
-
|
|
9024
|
+
self2.length++;
|
|
9025
9025
|
return inserted;
|
|
9026
9026
|
}
|
|
9027
|
-
function push(
|
|
9028
|
-
|
|
9029
|
-
if (!
|
|
9030
|
-
|
|
9027
|
+
function push(self2, item) {
|
|
9028
|
+
self2.tail = new Node(item, self2.tail, null, self2);
|
|
9029
|
+
if (!self2.head) {
|
|
9030
|
+
self2.head = self2.tail;
|
|
9031
9031
|
}
|
|
9032
|
-
|
|
9032
|
+
self2.length++;
|
|
9033
9033
|
}
|
|
9034
|
-
function unshift(
|
|
9035
|
-
|
|
9036
|
-
if (!
|
|
9037
|
-
|
|
9034
|
+
function unshift(self2, item) {
|
|
9035
|
+
self2.head = new Node(item, null, self2.head, self2);
|
|
9036
|
+
if (!self2.tail) {
|
|
9037
|
+
self2.tail = self2.head;
|
|
9038
9038
|
}
|
|
9039
|
-
|
|
9039
|
+
self2.length++;
|
|
9040
9040
|
}
|
|
9041
9041
|
function Node(value, prev, next, list) {
|
|
9042
9042
|
if (!(this instanceof Node)) {
|
|
@@ -18037,7 +18037,7 @@ var RedisCache = class extends Cache {
|
|
|
18037
18037
|
status: response.status,
|
|
18038
18038
|
statusText: response.statusText,
|
|
18039
18039
|
headers,
|
|
18040
|
-
body:
|
|
18040
|
+
body: btoa(String.fromCharCode(...new Uint8Array(body))),
|
|
18041
18041
|
cachedAt: Date.now(),
|
|
18042
18042
|
ttl: this.defaultTTL
|
|
18043
18043
|
};
|
|
@@ -18046,7 +18046,7 @@ var RedisCache = class extends Cache {
|
|
|
18046
18046
|
* Deserialize cache entry to Response
|
|
18047
18047
|
*/
|
|
18048
18048
|
deserializeResponse(entry) {
|
|
18049
|
-
const body =
|
|
18049
|
+
const body = Uint8Array.from(atob(entry.body), (c) => c.charCodeAt(0));
|
|
18050
18050
|
return new Response(body, {
|
|
18051
18051
|
status: entry.status,
|
|
18052
18052
|
statusText: entry.statusText,
|
|
@@ -18164,7 +18164,7 @@ var RedisCache = class extends Cache {
|
|
|
18164
18164
|
try {
|
|
18165
18165
|
const value = await this.client.get(key);
|
|
18166
18166
|
if (value) {
|
|
18167
|
-
totalSize +=
|
|
18167
|
+
totalSize += new TextEncoder().encode(value).length;
|
|
18168
18168
|
}
|
|
18169
18169
|
} catch {
|
|
18170
18170
|
}
|
package/src/redis-cache.js
CHANGED
|
@@ -58,7 +58,7 @@ var RedisCache = class extends Cache {
|
|
|
58
58
|
status: response.status,
|
|
59
59
|
statusText: response.statusText,
|
|
60
60
|
headers,
|
|
61
|
-
body:
|
|
61
|
+
body: btoa(String.fromCharCode(...new Uint8Array(body))),
|
|
62
62
|
cachedAt: Date.now(),
|
|
63
63
|
ttl: this.defaultTTL
|
|
64
64
|
};
|
|
@@ -67,7 +67,7 @@ var RedisCache = class extends Cache {
|
|
|
67
67
|
* Deserialize cache entry to Response
|
|
68
68
|
*/
|
|
69
69
|
deserializeResponse(entry) {
|
|
70
|
-
const body =
|
|
70
|
+
const body = Uint8Array.from(atob(entry.body), (c) => c.charCodeAt(0));
|
|
71
71
|
return new Response(body, {
|
|
72
72
|
status: entry.status,
|
|
73
73
|
statusText: entry.statusText,
|
|
@@ -185,7 +185,7 @@ var RedisCache = class extends Cache {
|
|
|
185
185
|
try {
|
|
186
186
|
const value = await this.client.get(key);
|
|
187
187
|
if (value) {
|
|
188
|
-
totalSize +=
|
|
188
|
+
totalSize += new TextEncoder().encode(value).length;
|
|
189
189
|
}
|
|
190
190
|
} catch {
|
|
191
191
|
}
|