Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
440 changes: 218 additions & 222 deletions examples/redis-minimal/package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions examples/redis-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
"lint": "next lint"
},
"dependencies": {
"@fortedigital/nextjs-cache-handler": "^2.0.0-canary12",
"next": "15.3.4",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"redis": "^5.5.6"
"@fortedigital/nextjs-cache-handler": "^2.0.0",
"next": "15.4.1",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"redis": "^5.6.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/node": "^24",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.3.4",
"eslint-config-next": "15.4.1",
"tailwindcss": "^4",
"typescript": "^5"
}
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/nextjs-cache-handler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/nextjs-cache-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"next",
"redis"
],
"version": "2.0.0",
"version": "2.0.1",
"type": "module",
"license": "MIT",
"description": "Next.js cache handlers",
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs-cache-handler/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const REVALIDATED_TAGS_KEY = "__revalidated_tags__";
export const REVALIDATED_TAGS_KEY = "__revalidated_tags__";
4 changes: 2 additions & 2 deletions packages/nextjs-cache-handler/src/handlers/cache-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
} from "./cache-handler.types";
import { PrerenderManifest } from "next/dist/build";
import {
type CachedFetchValue,
type IncrementalCachedPageValue,
type GetIncrementalResponseCacheContext,
type GetIncrementalFetchCacheContext,
IncrementalCacheValue,
} from "next/dist/server/response-cache/types";
import { resolveRevalidateValue } from "../helpers/resolveRevalidateValue";

const PRERENDER_MANIFEST_VERSION = 4;

Expand Down Expand Up @@ -651,7 +651,7 @@ export class CacheHandler implements NextCacheHandler {

const { tags = [], internal_lastModified } = ctx ?? {};

const revalidate = (incrementalCacheValue as CachedFetchValue)?.revalidate;
const revalidate = resolveRevalidateValue(incrementalCacheValue, ctx);

const lastModified = Math.round(internal_lastModified ?? Date.now());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
type CachedFetchValue,
IncrementalCachedAppPageValue,
SetIncrementalResponseCacheContext,
} from "next/dist/server/response-cache";
import {
CacheHandlerParametersSet,
Revalidate,
} from "../handlers/cache-handler.types";

/**
* Resolved revalidate value based on type of the cached value.
*
* @param incrementalCacheValue - Todo
* @param ctx - todo
*
* @returns Cache revalidate value.
*/
export function resolveRevalidateValue(
incrementalCacheValue: CacheHandlerParametersSet[1],
ctx: CacheHandlerParametersSet[2] & {
revalidate?: Revalidate;
},
) {
const cachedFetchValue = incrementalCacheValue as CachedFetchValue;
const cachedPageValue =
incrementalCacheValue as IncrementalCachedAppPageValue;
const responseCacheCtx = ctx as SetIncrementalResponseCacheContext;

let revalidate;

if (cachedFetchValue.kind === "FETCH") {
revalidate = cachedFetchValue.revalidate;
} else if (cachedPageValue.kind === "APP_PAGE") {
revalidate = responseCacheCtx.cacheControl?.revalidate;
}

return revalidate ?? ctx.revalidate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import type { OutgoingHttpHeaders } from "http";
import { getTagsFromHeaders } from "../helpers/getTagsFromHeaders";
import { Revalidate } from "../handlers/cache-handler.types";
import { resolveRevalidateValue } from "../helpers/resolveRevalidateValue";

type CacheHandlerType = typeof import("../handlers/cache-handler").CacheHandler;

Expand Down Expand Up @@ -392,9 +393,11 @@ export async function registerInitialCache(
return;
}

const revalidateValue = fetchCache.revalidate;

// HACK: By default, Next.js sets the revalidate option to CACHE_ONE_YEAR if the revalidate option is set
const revalidate =
fetchCache.revalidate === CACHE_ONE_YEAR ? false : fetchCache.revalidate;
revalidateValue === CACHE_ONE_YEAR ? false : revalidateValue;

try {
await cacheHandler.set(fetchCacheKey, fetchCache, {
Expand Down