perf: implement local L1 memory cache in front of Upstash Redis#400
Open
YashKrTripathi wants to merge 4 commits into
Open
perf: implement local L1 memory cache in front of Upstash Redis#400YashKrTripathi wants to merge 4 commits into
YashKrTripathi wants to merge 4 commits into
Conversation
|
@YashKrTripathi is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
@Priyanshu-byte-coder If any changes are needed, please let me know and I’ll make them. If everything looks good and you’re satisfied with the implementation, please approve and merge it. |
Priyanshu-byte-coder
requested changes
May 20, 2026
Owner
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
- Unbounded memory growth — module-level Map with no eviction. Add max-size cap (LRU at ~500 entries) or document serverless-only assumption. 2. value: any — use unknown with cast on return. Architecture (memory L1 → Redis L2) is sound, bypass logic correct.
Author
Status: Changes Implemented that you asked @Priyanshu-byte-coder , What I changed
Files modified
Verification performed
Branch / Commit
|
Author
|
@Priyanshu-byte-coder PLEASE CHECK AND REVERT BACK! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @Priyanshu-byte-coder here is the new focused pr please have a look:
Description
This PR implements a fast, server-side in-memory L1 cache layer in front of the existing Upstash Redis (L2) cache helper (
withMetricsCache).By performing an$O(1)$ local memory lookup before sending network requests to Redis, this optimization significantly reduces latency for dashboard metric updates, prevents Redis rate-limit consumption during high traffic, and gracefully falls back to a pure in-memory cache for local development when Upstash environment variables are not configured.
Changes
memoryCacheMap withinsrc/lib/metrics-cache.ts.withMetricsCachefunction to:refresh/sync/bypassCache) ignore both cache levels and rewrite the fresh data to both layers.