Skip to content

Commit c31f6fc

Browse files
committed
add a new shouldBypassTagCache that could be used by incremental caches on get
1 parent 352e4b2 commit c31f6fc

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/open-next/src/adapters/cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class Cache {
6363

6464
const _tags = [...(tags ?? []), ...(softTags ?? [])];
6565
const _lastModified = cachedEntry.lastModified ?? Date.now();
66-
const _hasBeenRevalidated = await hasBeenRevalidated(
66+
const _hasBeenRevalidated = cachedEntry.shouldBypassTagCache ? false : await hasBeenRevalidated(
6767
key,
6868
_tags,
6969
cachedEntry,
@@ -82,7 +82,7 @@ export default class Cache {
8282
!tag.endsWith("page"),
8383
);
8484
if (path) {
85-
const hasPathBeenUpdated = await hasBeenRevalidated(
85+
const hasPathBeenUpdated = cachedEntry.shouldBypassTagCache ? false : await hasBeenRevalidated(
8686
path.replace("_N_T_/", ""),
8787
[],
8888
cachedEntry,
@@ -118,7 +118,7 @@ export default class Cache {
118118
const meta = cacheData.meta;
119119
const tags = getTagsFromValue(cacheData);
120120
const _lastModified = cachedEntry.lastModified ?? Date.now();
121-
const _hasBeenRevalidated = await hasBeenRevalidated(
121+
const _hasBeenRevalidated = cachedEntry.shouldBypassTagCache ? false : await hasBeenRevalidated(
122122
key,
123123
tags,
124124
cachedEntry,

packages/open-next/src/adapters/composable-cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
globalThis.tagCache.mode === "nextMode" &&
2929
result.value.tags.length > 0
3030
) {
31-
const hasBeenRevalidated = await globalThis.tagCache.hasBeenRevalidated(
31+
const hasBeenRevalidated = result.shouldBypassTagCache ? false : await globalThis.tagCache.hasBeenRevalidated(
3232
result.value.tags,
3333
result.lastModified,
3434
);
@@ -37,7 +37,7 @@ export default {
3737
globalThis.tagCache.mode === "original" ||
3838
globalThis.tagCache.mode === undefined
3939
) {
40-
const hasBeenRevalidated =
40+
const hasBeenRevalidated = result.shouldBypassTagCache ? false :
4141
(await globalThis.tagCache.getLastModified(
4242
cacheKey,
4343
result.lastModified,

packages/open-next/src/types/overrides.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export type CachedFetchValue = {
9393
export type WithLastModified<T> = {
9494
lastModified?: number;
9595
value?: T;
96+
/**
97+
* If set to true, we will not check the tag cache for this entry.
98+
* `revalidateTag` and `revalidatePath` may not work as expected.
99+
*/
100+
shouldBypassTagCache?: boolean;
96101
};
97102

98103
export type CacheEntryType = Extension;

0 commit comments

Comments
 (0)