Next.js Discord

Discord Forum

How to cache stream in route.ts and Confuse about fetch request-memoization

Unanswered
Turkish Van posted this in #help-forum
Open in Discord
Turkish VanOP
### Background
I have built a NextJs project which expose a API that return a stream. I wonder how can I cache the stream response.

### How to cache stream api route

I have tried following methods,
1. export const revalidate=3600 // in my route.ts file
2. fetch("/api/xxx", { next : { revalidate: 60}}) // the fetch is wrapped in a hook, and call at a component
But either of them work. So can anyone know how to cache http stream.

### Problem about fetch request-memoization

Sometimes I swtich page, by browser' s navigator, forwarding and backing . I found fetch "/api/xxx" should be cached on the disk (the response showed http status code 200 (from disk cache)) , but the cached data is only part of full data. I am confused about it. May it be the [Request Memoization](https://nextjs.org/docs/app/building-your-application/caching#request-memoization) problem ?

0 Replies