Skip to content

Commit

Permalink
Merge pull request #67 from replicate/ratelimit-cache
Browse files Browse the repository at this point in the history
Experiment with in-memory ephemeralCache
  • Loading branch information
aron authored Dec 8, 2023
2 parents 0091e33 + 966233a commit 1c5e848
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { NextRequest, NextResponse } from 'next/server';
import { Ratelimit } from '@upstash/ratelimit';
import { kv } from '@vercel/kv';

const ephemeralCache = new Map();

const ratelimit = new Ratelimit({
redis: kv,
// 20 requests from the same IP within a 10 second sliding window
limiter: Ratelimit.slidingWindow(20, '10s'),
prefix: `v2/zoo/ratelimit/${process.env.VERCEL_ENV ?? 'local'}`,
timeout: 500,
ephemeralCache,
});

// Rate limit the /api/predictions/[id] endpoint
Expand Down

1 comment on commit 1c5e848

@vercel
Copy link

@vercel vercel bot commented on 1c5e848 Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.