Skip to content

Commit 966233a

Browse files
committed
Experiment with in-memory ephemeralCache
Should reduce the load on the redis key-value store...
1 parent 0091e33 commit 966233a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

middleware.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { NextRequest, NextResponse } from 'next/server';
22
import { Ratelimit } from '@upstash/ratelimit';
33
import { kv } from '@vercel/kv';
44

5+
const ephemeralCache = new Map();
6+
57
const ratelimit = new Ratelimit({
68
redis: kv,
79
// 20 requests from the same IP within a 10 second sliding window
810
limiter: Ratelimit.slidingWindow(20, '10s'),
911
prefix: `v2/zoo/ratelimit/${process.env.VERCEL_ENV ?? 'local'}`,
1012
timeout: 500,
13+
ephemeralCache,
1114
});
1215

1316
// Rate limit the /api/predictions/[id] endpoint

0 commit comments

Comments
 (0)