@vizamodo/edge-cache-core 0.3.33 → 0.3.35
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/dist/runtime/cache.js
CHANGED
|
@@ -52,9 +52,14 @@ export async function getCachedOrFetch(key, fetcher, options) {
|
|
|
52
52
|
else {
|
|
53
53
|
unwrapped = raw;
|
|
54
54
|
}
|
|
55
|
-
// Write to edge cache (
|
|
55
|
+
// Write to edge cache (must await to ensure commit before worker exits).
|
|
56
56
|
if (edgeTtlSec > 0) {
|
|
57
|
-
|
|
57
|
+
try {
|
|
58
|
+
await setEdgeCache(key, unwrapped, edgeTtlSec);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// best-effort: do not break response on cache failure
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
// ttlMs for L1 = same window as edge TTL so both layers expire together.
|
|
60
65
|
const l1TtlMs = edgeTtlSec * 1000;
|
|
@@ -75,8 +75,12 @@ export async function setEdgeCache(key, value, ttlSec) {
|
|
|
75
75
|
});
|
|
76
76
|
try {
|
|
77
77
|
console.debug("[edge-cache] SET BODY SIZE", { key, size: body.length });
|
|
78
|
+
const t0 = Date.now();
|
|
78
79
|
await cache.put(req, res);
|
|
79
|
-
|
|
80
|
+
// Force event loop flush to ensure write completes before worker exits
|
|
81
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
82
|
+
const t1 = Date.now();
|
|
83
|
+
console.debug("[edge-cache] SET OK", { key, durationMs: t1 - t0 });
|
|
80
84
|
}
|
|
81
85
|
catch (err) {
|
|
82
86
|
console.error("[edge-cache] SET FAILED", { key, err });
|