我有一个 nextjs 应用程序,使用 nextjs 13 和应用程序路由器。一个端点返回一个 randomInt:
import { randomInt } from "crypto";
import { NextResponse } from "next/server";
export async function GET() {
return NextResponse.json({ revenue: randomInt(100) });
}
在本地,每次加载此端点时,我都会得到不同的数字。但是当在 vercel 上的 prod 中时,我总是得到相同的数字,就像它被缓存一样。我怎样才能禁用它?
如果确实是缓存问题,可以尝试使用fetch函数参数。比如:
fetch("[path]", {
method: "GET",
cache: "no-store",
})
还有一些其他参数和选项需要查找,只需查看他们的网站或“RequestInit”界面即可。