@leejpsd/nextjs-cache-handler 0.3.0 → 0.3.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/CHANGELOG.md +14 -0
- package/dist/cache-components/index.cjs +19 -12
- package/dist/cache-components/index.cjs.map +1 -1
- package/dist/cache-components/index.js +19 -12
- package/dist/cache-components/index.js.map +1 -1
- package/dist/index.cjs +19 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -12
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/dist/index.cjs
CHANGED
|
@@ -989,47 +989,54 @@ async function getImpl(state, cacheKey, softTags) {
|
|
|
989
989
|
});
|
|
990
990
|
return void 0;
|
|
991
991
|
}
|
|
992
|
-
|
|
992
|
+
const freshnessTags = softTags.length > 0 ? [...softTags, ...envelope.tags] : envelope.tags;
|
|
993
|
+
let tagStale = false;
|
|
994
|
+
if (freshnessTags.length > 0) {
|
|
993
995
|
let mostRecent = 0;
|
|
994
|
-
for (const t of
|
|
996
|
+
for (const t of freshnessTags) {
|
|
995
997
|
const ts = state.localTagTimestamps.get(t);
|
|
996
998
|
if (ts !== void 0 && ts > mostRecent) mostRecent = ts;
|
|
997
999
|
}
|
|
998
1000
|
if (mostRecent > envelope.timestamp) {
|
|
999
|
-
state.
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1001
|
+
if (state.opts.staleWhileRevalidate && partition.freshness !== "expired") {
|
|
1002
|
+
tagStale = true;
|
|
1003
|
+
} else {
|
|
1004
|
+
state.emit({ type: "cache.miss", meta: { reason: "tag-invalidated" } });
|
|
1005
|
+
return void 0;
|
|
1006
|
+
}
|
|
1004
1007
|
}
|
|
1005
1008
|
}
|
|
1006
|
-
|
|
1009
|
+
const freshness = tagStale ? "stale" : partition.freshness;
|
|
1010
|
+
if (freshness === "stale") {
|
|
1011
|
+
const staleMeta = tagStale ? { freshness, reason: "tag-invalidated" } : { freshness };
|
|
1007
1012
|
if (state.opts.singleFlight) {
|
|
1008
1013
|
const isLeader = await tryAcquireRefreshLock(state, cacheKey);
|
|
1009
1014
|
state.emit({
|
|
1010
1015
|
type: isLeader ? "cache.stale.refresh.leader" : "cache.stale.refresh.follower",
|
|
1011
1016
|
ms: Date.now() - start,
|
|
1012
|
-
meta:
|
|
1017
|
+
meta: staleMeta
|
|
1013
1018
|
});
|
|
1014
1019
|
} else {
|
|
1015
1020
|
state.emit({
|
|
1016
1021
|
type: "cache.stale",
|
|
1017
1022
|
ms: Date.now() - start,
|
|
1018
|
-
meta:
|
|
1023
|
+
meta: staleMeta
|
|
1019
1024
|
});
|
|
1020
1025
|
}
|
|
1021
1026
|
} else {
|
|
1022
1027
|
state.emit({
|
|
1023
1028
|
type: "cache.hit",
|
|
1024
1029
|
ms: Date.now() - start,
|
|
1025
|
-
meta: { freshness
|
|
1030
|
+
meta: { freshness }
|
|
1026
1031
|
});
|
|
1027
1032
|
}
|
|
1033
|
+
const revalidateMs = Math.max(0, envelope.revalidate) * 1e3;
|
|
1034
|
+
const outTimestamp = tagStale ? Math.min(envelope.timestamp, Date.now() - revalidateMs - 1) : envelope.timestamp;
|
|
1028
1035
|
return {
|
|
1029
1036
|
value: bufferToStream(Buffer.from(envelope.value, "base64")),
|
|
1030
1037
|
tags: envelope.tags,
|
|
1031
1038
|
stale: envelope.stale,
|
|
1032
|
-
timestamp:
|
|
1039
|
+
timestamp: outTimestamp,
|
|
1033
1040
|
expire: envelope.expire,
|
|
1034
1041
|
revalidate: envelope.revalidate
|
|
1035
1042
|
};
|