Skip to content

Commit

Permalink
prevent response caching in next.js
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed May 23, 2024
1 parent 421025d commit da485b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/api/predictions/[id]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions app/api/predictions/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit da485b1

Please sign in to comment.