Next.js Discord

Discord Forum

Cache behaviour for fetch function in route handler

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Hi everyone, I'm studying how the fetch function in a route handler behaves when interacting with blob storage in vercel.
I have the following endpoint:
// /api/tokens
import { type TokensResponse } from "@lifi/sdk"
import { NextResponse } from "next/server"

import { newVercelConfig } from "@/configServerless"

export type TokensResponseWithTimestamps = TokensResponse & {
  chainUpdateTimestampMS: { [chainId: number]: number }
}

export async function GET() {
  try {
    const fullUrl = `${newVercelConfig.storage.baseUrl}chains`
    const response = await fetch(fullUrl)
    return NextResponse.json({
      tokens: response,
    })
  } catch (e: unknown) {
    console.error(e)
    return Response.json({ message: "Failed to process request", error: e })
  }
}

This endpoint fetches the content of a storage I have setup. It returns a JSON of 2.4MB.
I can't use the nextjs cache because the size is over 2MB, so what happens if I leave it as it is? The blob resource has a cache of X days. I'm wondering if the nextjs caches the fetch call or not.

0 Replies