@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 CHANGED
@@ -1,5 +1,19 @@
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
+
9
+ ## 0.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`f07e91b`](https://github.com/leejpsd/nextjs-cache-handler/commit/f07e91b432be6d52885f2f0a83bfb6c63d519bbe) Thanks [@leejpsd](https://github.com/leejpsd)! - Refresh the npm package description and keywords for the 0.3 feature set:
14
+ Next.js 15/16, built-in compression, Redis Sentinel, OpenTelemetry, and the
15
+ multi-instance AWS validation results.
16
+
3
17
  ## 0.3.0
4
18
 
5
19
  ### Minor Changes
@@ -975,47 +975,54 @@ async function getImpl(state, cacheKey, softTags) {
975
975
  });
976
976
  return void 0;
977
977
  }
978
- if (softTags.length > 0) {
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 softTags) {
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.emit({
986
- type: "cache.miss",
987
- meta: { reason: "soft-tag-invalidated" }
988
- });
989
- return void 0;
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
- if (partition.freshness === "stale") {
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: { freshness: partition.freshness }
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: { freshness: partition.freshness }
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: partition.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: envelope.timestamp,
1025
+ timestamp: outTimestamp,
1019
1026
  expire: envelope.expire,
1020
1027
  revalidate: envelope.revalidate
1021
1028
  };