Skip to content

Commit 31c3740

Browse files
authored
fix(cacheInterceptor): route cache handling (opennextjs#959)
1 parent 9a83eb7 commit 31c3740

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

.changeset/light-needles-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
fix(cacheInterceptor): route cache handling

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ export async function cacheInterceptor(
228228
return event;
229229
}
230230
// We need to check the tag cache now
231-
if (cachedData.value?.type === "app") {
231+
if (
232+
cachedData.value?.type === "app" ||
233+
cachedData.value?.type === "route"
234+
) {
232235
const tags = getTagsFromValue(cachedData.value);
233236
const _hasBeenRevalidated = await hasBeenRevalidated(
234237
localizedPath,

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe("cacheInterceptor", () => {
153153
);
154154
});
155155

156-
it("should take no action when tagCache lasModified is -1", async () => {
156+
it("should take no action when tagCache lasModified is -1 for app type", async () => {
157157
const event = createEvent({
158158
url: "/albums",
159159
});
@@ -170,6 +170,25 @@ describe("cacheInterceptor", () => {
170170
expect(result).toEqual(event);
171171
});
172172

173+
it("should take no action when tagCache lasModified is -1 for route type", async () => {
174+
const event = createEvent({
175+
url: "/albums",
176+
});
177+
178+
const body = "route";
179+
incrementalCache.get.mockResolvedValueOnce({
180+
value: {
181+
type: "route",
182+
body: body,
183+
revalidate: false,
184+
},
185+
lastModified: new Date("2024-01-01T23:58:00Z").getTime(),
186+
});
187+
tagCache.getLastModified.mockResolvedValueOnce(-1);
188+
const result = await cacheInterceptor(event);
189+
expect(result).toEqual(event);
190+
});
191+
173192
it("should retrieve page router content from stale cache", async () => {
174193
const event = createEvent({
175194
url: "/revalidate",
@@ -263,7 +282,7 @@ describe("cacheInterceptor", () => {
263282
);
264283
});
265284

266-
it("should take no action when cache returns unrecoginsed type", async () => {
285+
it("should take no action when cache returns unrecognized type", async () => {
267286
const event = createEvent({
268287
url: "/albums",
269288
});

0 commit comments

Comments
 (0)