perf: cache metrics api requests with 1 hour revalidation#362
perf: cache metrics api requests with 1 hour revalidation#362YashKrTripathi wants to merge 1 commit 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. |
|
Hi! @Priyanshu-byte-coder , This PR (#362 — Please let me know your thoughts on the caching trade-offs here. Once approved, please label it with the |
|
This approach has a security vulnerability and cannot be merged as-is. Cross-user data leak via shared fetch cache Next.js
This affects every route using a static-ish URL:
The correct approach for authenticated caching is a server-side cache keyed by |
Sorry for the inconvenience caused will try asap to fix this issue |
|
@Priyanshu-byte-coder I am working on this pr until then please close the other one the copy button pr with the gssoc:aprooved tag pls |
e73fa62 to
307f90d
Compare
@Priyanshu-byte-coder As requested, the feature set has been split into two separate PRs:
Please close the duplicate PR #269 and merge this PR (#362). Once merged/approved, please apply the |
307f90d to
01b3cf2
Compare
|
@Priyanshu-byte-coder i am resolving conflicts please wait |
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
The token-hashed cache key approach (getCacheKey(token, namespace)) is correct — no cross-user data leaks. However, PR #311 (Upstash Redis caching) was just merged and already adds per-user caching for the same routes (streak, contributions, prs, repos) using Redis with proper TTLs.
Merging this PR would create two competing caching layers for the same data, with different TTLs and no coordination. When the Redis cache is empty (cold start, expired, or bypass), the in-memory cache could serve stale data from a previous request. When the in-memory cache is cleared (cold start), the overhead is pointless.
Please close this PR — the caching problem is solved by #311. If you want to improve the in-memory cache (e.g., as a faster L1 cache in front of Redis), open a new focused PR that integrates with the existing withMetricsCache interface from src/lib/metrics-cache.ts.
yes raising this new issue asap please wait sir and assign that issue to me i am already in the project i can do that right now |
01b3cf2 to
0f1a358
Compare
@Priyanshu-byte-coder Thanks for the clarification. I’ve opened a new focused PR: perf: implement local L1 memory cache in front of Upstash Redis (#400) that aligns with the existing caching architecture. Since PR #311 already solves the original caching issue, I’m closing this PR to avoid duplicate caching layers and potential inconsistencies. |
Description
This Pull Request implements a Next.js caching strategy (
next: { revalidate: 3600 }) across the main GitHub metrics endpoints to optimize dashboard response times and conserve GitHub API rate limits.This PR was split from #269 as requested by the mentor to allow for a dedicated discussion on the caching trade-offs.
Key Changes
cache: "no-store"withnext: { revalidate: 3600 }(1-hour TTL) across the following metrics API endpoints:src/lib/github.ts(issues, month counts)src/app/api/metrics/contributions/route.tssrc/app/api/metrics/languages/route.tssrc/app/api/metrics/pinned-repos/route.tssrc/app/api/metrics/pr-breakdown/route.tssrc/app/api/metrics/prs/route.tssrc/app/api/metrics/repo-health/route.tssrc/app/api/metrics/repos/route.tssrc/app/api/metrics/streak/route.tssrc/app/api/metrics/weekly-summary/route.tsTrade-offs / Discussion
Using
cache: "no-store"causes fresh upstream requests to the GitHub API on every single component mount, which can exhaust the user's GitHub API rate limits very quickly under active usage. Adding a 1-hour revalidation window mitigates this rate-limit issue while keeping the dashboard data reasonably fresh.