@leejpsd/nextjs-cache-handler 0.3.2 → 0.3.4

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/index.js CHANGED
@@ -1564,8 +1564,35 @@ var IncrementalRedisCacheHandler = class {
1564
1564
  this.state.emit({ type: "cache.miss", meta: { reason: "tag-state-expired" } });
1565
1565
  return null;
1566
1566
  }
1567
+ let lastModified = parsed.lastModified;
1568
+ if (!isFetch && typeof lastModified === "number") {
1569
+ const softTs = Math.max(
1570
+ 0,
1571
+ ...tagStates.map(
1572
+ (s) => s && typeof s.stale === "number" ? s.stale : 0
1573
+ )
1574
+ );
1575
+ if (softTs >= lastModified) {
1576
+ const rev = parsed.revalidateSec;
1577
+ if (typeof rev !== "number" || rev <= 0 || rev >= ONE_YEAR_SEC2) {
1578
+ this.state.emit({
1579
+ type: "cache.miss",
1580
+ meta: { reason: "tag-invalidated" }
1581
+ });
1582
+ return null;
1583
+ }
1584
+ lastModified = Math.min(
1585
+ lastModified,
1586
+ Date.now() - (rev + 1) * 1e3
1587
+ );
1588
+ this.state.emit({
1589
+ type: "cache.stale",
1590
+ meta: { reason: "tag-invalidated" }
1591
+ });
1592
+ }
1593
+ }
1567
1594
  this.state.emit({ type: "cache.hit" });
1568
- return { ...parsed, tags };
1595
+ return { ...parsed, lastModified, tags };
1569
1596
  } catch (err) {
1570
1597
  this.state.logger.error("get() unexpected error", {
1571
1598
  message: err.message
@@ -1579,7 +1606,11 @@ var IncrementalRedisCacheHandler = class {
1579
1606
  const tags = extractTagsFromValue(data, ctx);
1580
1607
  const useLocal = shouldUseLocalIncrementalStore(tags);
1581
1608
  const ttl = normalizeTtlSeconds(data, ctx);
1582
- const record = { lastModified: Date.now(), value: data };
1609
+ const record = {
1610
+ lastModified: Date.now(),
1611
+ value: data,
1612
+ revalidateSec: ttl
1613
+ };
1583
1614
  const serialized = serializeCacheRecord(record);
1584
1615
  const eKey = entryKey2(this.state, cacheKey);
1585
1616
  this.requestMemo.delete(eKey);