Skip to content

Commit 3e48436

Browse files
authored
fix: allow bypassing the Tag Cache in the interceptor (#982)
1 parent fd95b22 commit 3e48436

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

.changeset/gold-penguins-walk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": minor
3+
---
4+
5+
fix: allow bypassing the Tag Cache in the interceptor

packages/open-next/src/core/routing/cacheInterceptor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ export async function cacheInterceptor(
233233
cachedData.value?.type === "route"
234234
) {
235235
const tags = getTagsFromValue(cachedData.value);
236-
const _hasBeenRevalidated = await hasBeenRevalidated(
237-
localizedPath,
238-
tags,
239-
cachedData,
240-
);
236+
237+
const _hasBeenRevalidated = cachedData.shouldBypassTagCache
238+
? false
239+
: await hasBeenRevalidated(localizedPath, tags, cachedData);
240+
241241
if (_hasBeenRevalidated) {
242242
return event;
243243
}

packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ describe("cacheInterceptor", () => {
170170
expect(result).toEqual(event);
171171
});
172172

173+
it("should bypass the tag cache when shouldBypassTagCache is true", async () => {
174+
const event = createEvent({
175+
url: "/albums",
176+
});
177+
incrementalCache.get.mockResolvedValueOnce({
178+
value: {
179+
type: "app",
180+
html: "Hello, world!",
181+
},
182+
shouldBypassTagCache: true,
183+
});
184+
185+
await cacheInterceptor(event);
186+
187+
expect(tagCache.getLastModified).not.toHaveBeenCalled();
188+
});
189+
173190
it("should take no action when tagCache lasModified is -1 for route type", async () => {
174191
const event = createEvent({
175192
url: "/albums",

0 commit comments

Comments
 (0)