Skip to content

Commit

Permalink
Site Cache Handler: disable Full Route Cache (#522)
Browse files Browse the repository at this point in the history
Detect Full Route Cache by checking if the key starts with "/", as Full Route Cache keys are the page url (and start with /), data caches are a hash.
  • Loading branch information
nsams authored Nov 18, 2024
1 parent 2853ea9 commit 98160e4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions site/cache-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ function parseBodyForGqlError(body: string) {
}
}

function isCacheKeyFullRoute(key: string) {
//full-route-cache keys are the page url (and start with /), data caches are a hash
return key.startsWith("/");
}

export default class CacheHandler {
async get(key: string): ReturnType<NextCacheHandler["get"]> {
if (isCacheKeyFullRoute(key)) {
return null;
}
if (redis.status === "ready") {
try {
const redisResponse = await redis.get(key);
Expand All @@ -76,6 +84,10 @@ export default class CacheHandler {
}

async set(key: string, value: Parameters<NextCacheHandler["set"]>[1]): Promise<void> {
if (isCacheKeyFullRoute(key)) {
return;
}

if (value?.kind === "FETCH") {
const responseBody = parseBodyForGqlError(value.data.body);
if (responseBody?.errors) {
Expand Down

0 comments on commit 98160e4

Please sign in to comment.