@leejpsd/nextjs-cache-handler 0.3.1 → 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 +6 -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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`6f35ff3`](https://github.com/leejpsd/nextjs-cache-handler/commit/6f35ff3d6eb6d84a842b8afc2677ae2545e2deba) Thanks [@leejpsd](https://github.com/leejpsd)! - Fix: soft revalidation of explicit `cacheTag()` tags — `revalidateTag(tag, "max")` — was a no-op on time-fresh entries. `get()` now folds the entry's own tags into the freshness check and serves tag-invalidated entries as stale-while-revalidate (backdated past `revalidate` so Next schedules a background re-render), matching the spec's soft-invalidation semantics. Hard invalidation (`{ expire: 0 }`) was already correct. Thanks to @eveyrat for the report (#1) and @unitedworldwrestling for the fix approach (#2).
|
|
8
|
+
|
|
3
9
|
## 0.3.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -975,47 +975,54 @@ async function getImpl(state, cacheKey, softTags) {
|
|
|
975
975
|
});
|
|
976
976
|
return void 0;
|
|
977
977
|
}
|
|
978
|
-
|
|
978
|
+
const freshnessTags = softTags.length > 0 ? [...softTags, ...envelope.tags] : envelope.tags;
|
|
979
|
+
let tagStale = false;
|
|
980
|
+
if (freshnessTags.length > 0) {
|
|
979
981
|
let mostRecent = 0;
|
|
980
|
-
for (const t of
|
|
982
|
+
for (const t of freshnessTags) {
|
|
981
983
|
const ts = state.localTagTimestamps.get(t);
|
|
982
984
|
if (ts !== void 0 && ts > mostRecent) mostRecent = ts;
|
|
983
985
|
}
|
|
984
986
|
if (mostRecent > envelope.timestamp) {
|
|
985
|
-
state.
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
987
|
+
if (state.opts.staleWhileRevalidate && partition.freshness !== "expired") {
|
|
988
|
+
tagStale = true;
|
|
989
|
+
} else {
|
|
990
|
+
state.emit({ type: "cache.miss", meta: { reason: "tag-invalidated" } });
|
|
991
|
+
return void 0;
|
|
992
|
+
}
|
|
990
993
|
}
|
|
991
994
|
}
|
|
992
|
-
|
|
995
|
+
const freshness = tagStale ? "stale" : partition.freshness;
|
|
996
|
+
if (freshness === "stale") {
|
|
997
|
+
const staleMeta = tagStale ? { freshness, reason: "tag-invalidated" } : { freshness };
|
|
993
998
|
if (state.opts.singleFlight) {
|
|
994
999
|
const isLeader = await tryAcquireRefreshLock(state, cacheKey);
|
|
995
1000
|
state.emit({
|
|
996
1001
|
type: isLeader ? "cache.stale.refresh.leader" : "cache.stale.refresh.follower",
|
|
997
1002
|
ms: Date.now() - start,
|
|
998
|
-
meta:
|
|
1003
|
+
meta: staleMeta
|
|
999
1004
|
});
|
|
1000
1005
|
} else {
|
|
1001
1006
|
state.emit({
|
|
1002
1007
|
type: "cache.stale",
|
|
1003
1008
|
ms: Date.now() - start,
|
|
1004
|
-
meta:
|
|
1009
|
+
meta: staleMeta
|
|
1005
1010
|
});
|
|
1006
1011
|
}
|
|
1007
1012
|
} else {
|
|
1008
1013
|
state.emit({
|
|
1009
1014
|
type: "cache.hit",
|
|
1010
1015
|
ms: Date.now() - start,
|
|
1011
|
-
meta: { freshness
|
|
1016
|
+
meta: { freshness }
|
|
1012
1017
|
});
|
|
1013
1018
|
}
|
|
1019
|
+
const revalidateMs = Math.max(0, envelope.revalidate) * 1e3;
|
|
1020
|
+
const outTimestamp = tagStale ? Math.min(envelope.timestamp, Date.now() - revalidateMs - 1) : envelope.timestamp;
|
|
1014
1021
|
return {
|
|
1015
1022
|
value: bufferToStream(Buffer.from(envelope.value, "base64")),
|
|
1016
1023
|
tags: envelope.tags,
|
|
1017
1024
|
stale: envelope.stale,
|
|
1018
|
-
timestamp:
|
|
1025
|
+
timestamp: outTimestamp,
|
|
1019
1026
|
expire: envelope.expire,
|
|
1020
1027
|
revalidate: envelope.revalidate
|
|
1021
1028
|
};
|