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
5 changes: 5 additions & 0 deletions .changeset/light-needles-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix(cacheInterceptor): route cache handling
5 changes: 4 additions & 1 deletion packages/open-next/src/core/routing/cacheInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ export async function cacheInterceptor(
return event;
}
// We need to check the tag cache now
if (cachedData.value?.type === "app") {
if (
cachedData.value?.type === "app" ||
cachedData.value?.type === "route"
) {
const tags = getTagsFromValue(cachedData.value);
const _hasBeenRevalidated = await hasBeenRevalidated(
localizedPath,
Expand Down
23 changes: 21 additions & 2 deletions packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe("cacheInterceptor", () => {
);
});

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

it("should take no action when tagCache lasModified is -1 for route type", async () => {
const event = createEvent({
url: "/albums",
});

const body = "route";
incrementalCache.get.mockResolvedValueOnce({
value: {
type: "route",
body: body,
revalidate: false,
},
lastModified: new Date("2024-01-01T23:58:00Z").getTime(),
});
tagCache.getLastModified.mockResolvedValueOnce(-1);
const result = await cacheInterceptor(event);
expect(result).toEqual(event);
});

it("should retrieve page router content from stale cache", async () => {
const event = createEvent({
url: "/revalidate",
Expand Down Expand Up @@ -263,7 +282,7 @@ describe("cacheInterceptor", () => {
);
});

it("should take no action when cache returns unrecoginsed type", async () => {
it("should take no action when cache returns unrecognized type", async () => {
const event = createEvent({
url: "/albums",
});
Expand Down