From da485b15b5e8a58b965d00ce60e484f43ea66925 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 23 May 2024 09:30:29 -0700 Subject: [PATCH 1/2] prevent response caching in next.js --- app/api/predictions/[id]/route.js | 6 ++++++ app/api/predictions/route.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/api/predictions/[id]/route.js b/app/api/predictions/[id]/route.js index 99d788d2..15684fb6 100644 --- a/app/api/predictions/[id]/route.js +++ b/app/api/predictions/[id]/route.js @@ -5,6 +5,12 @@ const replicate = new Replicate({ auth: process.env.REPLICATE_API_TOKEN, }); +// Prevent Next.js / Vercel from caching responses +// See https://github.com/replicate/replicate-javascript/issues/136#issuecomment-1728053102 +replicate.fetch = (url, options) => { + return fetch(url, { ...options, cache: "no-store" }); +}; + export async function GET(request, {params}) { const { id } = params; const prediction = await replicate.predictions.get(id); diff --git a/app/api/predictions/route.js b/app/api/predictions/route.js index 9fc974cf..4fb2c974 100644 --- a/app/api/predictions/route.js +++ b/app/api/predictions/route.js @@ -5,6 +5,12 @@ const replicate = new Replicate({ auth: process.env.REPLICATE_API_TOKEN, }); +// Prevent Next.js / Vercel from caching responses +// See https://github.com/replicate/replicate-javascript/issues/136#issuecomment-1728053102 +replicate.fetch = (url, options) => { + return fetch(url, { ...options, cache: "no-store" }); +}; + // In production and preview deployments (on Vercel), the VERCEL_URL environment variable is set. // In development (on your local machine), the NGROK_HOST environment variable is set. const WEBHOOK_HOST = process.env.VERCEL_URL From d5cde8fe5d153ba46459793923b15e82b3a1b5a3 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 28 May 2024 15:26:40 -0700 Subject: [PATCH 2/2] Update app/api/predictions/[id]/route.js Co-authored-by: F --- app/api/predictions/[id]/route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/predictions/[id]/route.js b/app/api/predictions/[id]/route.js index 15684fb6..918af8cc 100644 --- a/app/api/predictions/[id]/route.js +++ b/app/api/predictions/[id]/route.js @@ -8,7 +8,7 @@ const replicate = new Replicate({ // Prevent Next.js / Vercel from caching responses // See https://github.com/replicate/replicate-javascript/issues/136#issuecomment-1728053102 replicate.fetch = (url, options) => { - return fetch(url, { ...options, cache: "no-store" }); + return fetch(url, { cache: "no-store", ...options }); }; export async function GET(request, {params}) {