Skip to content

feat(caching): implement stale-while-revalidate for GitHub API calls and set Cache-Control for SVG responses#8257

Merged
JhaSourav07 merged 2 commits into
JhaSourav07:mainfrom
Rakshak05:issue-#7252
Jul 23, 2026
Merged

feat(caching): implement stale-while-revalidate for GitHub API calls and set Cache-Control for SVG responses#8257
JhaSourav07 merged 2 commits into
JhaSourav07:mainfrom
Rakshak05:issue-#7252

Conversation

@Rakshak05

Copy link
Copy Markdown
Contributor

Description

Fixes #7252

This PR implements response caching with a stale-while-revalidate strategy for GitHub contributions API calls:

  • Caching Strategy: Contribution data is cached in Redis using a wrapped structure { data, fetchedAt }. Calls with age < 1 minute serve the cached data immediately. Calls with age < 1 hour serve cached data immediately and trigger a background revalidation. Other calls fetch synchronously and update the cache.
  • Quota Awareness: Background revalidation is paused if the worst-case remaining token quota drops below 100 points, protecting against rate limit exhaustion.
  • Cache-Control Header: Default SVG responses now have a static Cache-Control header of public, max-age=300, stale-while-revalidate=3600.
  • Tests & Quality: Updated and successfully ran all unit tests for the GitHub caching layer and API routes.

Pillar

  • 🎨 Pillar 1 — New Theme Design
  • 📐 Pillar 2 — Geometric SVG Improvement
  • 🕐 Pillar 3 — Timezone Logic Optimization
  • 🛠️ Other (Bug fix, refactoring, docs)

Visual Preview

N/A (Backend caching and header updates)

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

Copilot AI review requested due to automatic review settings July 22, 2026 10:25
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@Rakshak05 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@retenta-bot

retenta-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

This PR enhances the caching strategy for GitHub API calls by implementing a stale-while-revalidate approach, which should improve performance and user experience. It also sets a new Cache-Control header for SVG responses, aligning with previous decisions to ensure timely updates for users. Please refer to the related decision on updating Cache Control Headers for SVG Endpoints for additional context. Thank you for your contribution!

@retenta-bot retenta-bot Bot changed the title feat(caching): implement stale-while-revalidate for GitHub API calls and set Cache-Control for SVG responses-#7252 feat(caching): implement stale-while-revalidate for GitHub API calls and set Cache-Control for SVG responses Jul 22, 2026
@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jul 22, 2026
@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jul 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

✨ No significant bundle size changes detected.

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3985.28 KB 3985.28 KB 0 B
Total CSS 331.41 KB 331.41 KB 0 B

@Aamod007 Aamod007 added level:critical High-priority or mission-critical contributions affecting core systems, security, or infrastructure quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:performance Code changes that improve performance/speed mentor:Aamod007 labels Jul 23, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a massive performance and reliability upgrade! Implementing stale-while-revalidate caching and updating the HTTP cache-control headers for the SVG endpoints ensures blazing fast load times while keeping data fresh in the background. The changes to the caching layer and tests are well executed.

Excellent work on this!

Label Justification:

  • \level:critical: Assigned based on >= 4 files changed, fundamentally refactoring the caching architecture and updating all associated tests.
  • \quality:clean: Clean background revalidation logic and updated test cases.
  • \ ype:performance: Directly improves API response latency via SWR caching.
  • \mentor:Aamod007: Assigned as required.

@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label Jul 23, 2026
@JhaSourav07
JhaSourav07 merged commit 320530d into JhaSourav07:main Jul 23, 2026
9 of 10 checks passed
@github-actions github-actions Bot added this to the GSSoC 2026 milestone Jul 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @Rakshak05! Your PR has been successfully merged. 🚀

Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.

⚠️ Important for GSSoC Contributors:
You are strictly advised to join our Discord Server as it is mandatory for all GSSoC participants. All important announcements, point claims, and community discussions happen there.

Keep building! 💻✨

@Rakshak05
Rakshak05 deleted the issue-#7252 branch July 23, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved PR has been reviewed and accepted for valid contribution points level:critical High-priority or mission-critical contributions affecting core systems, security, or infrastructure mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:performance Code changes that improve performance/speed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement response caching with stale-while-revalidate for GitHub API calls

4 participants