Skip to content

Commit

Permalink
Merge pull request #104 from replicate/prevent-response-caching-in-ne…
Browse files Browse the repository at this point in the history
…xt.js

Prevent response caching in Next.js
  • Loading branch information
zeke committed May 28, 2024
2 parents 421025d + d5cde8f commit e840c5c
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, { cache: "no-store", ...options });
};

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 e840c5c

Please sign in to comment.