Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lua script caching #106

Merged
merged 7 commits into from
May 23, 2024
Merged

Add lua script caching #106

merged 7 commits into from
May 23, 2024

Conversation

CahidArda
Copy link
Contributor

No description provided.

before this commit, we loaded scripts to redis in every cold start. This is not so desirable because the scripts in the redis cache stay there unless someone calls SCRIPT FLUSH. Hence, a life cycle is needed.

How do we define a life cycle for a serverless environment? Random numbers. In each limit() invocation, we create a random number and flush the scripts if it is smaller than some frequency threshold. If a user makes a lot of requests, their scripts will get flushed eventually.

This implementation however, has a hazard: serverless instance A can flush while instance B is still operating. We need a 'safeEvalsha' and we add exactly that in hash.ts.
Copy link

linear bot commented May 22, 2024

Copy link

vercel bot commented May 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ratelimit-with-vercel-kv ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2024 4:06pm

@CahidArda CahidArda merged commit 4e06c13 into main May 23, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants