Skip to content

feat: implement caching for GitHub API responses#39

Closed
Ai-chan-0411 wants to merge 1 commit intoO2sa:mainfrom
Ai-chan-0411:feat/github-api-caching
Closed

feat: implement caching for GitHub API responses#39
Ai-chan-0411 wants to merge 1 commit intoO2sa:mainfrom
Ai-chan-0411:feat/github-api-caching

Conversation

@Ai-chan-0411
Copy link
Copy Markdown
Contributor

Summary

Closes #33

Adds in-memory caching for GitHub GraphQL API responses to reduce redundant API calls and improve response times.

Changes

  • lib/cache.ts — Generic cache with TTL-based expiration (default 5 min). Entries auto-expire on read.
  • lib/github.tsfetchGitHubUserData checks cache before calling GitHub API. Cache key is the lowercased username.
  • app/api/compare/route.ts — Adds Cache-Control: public, s-maxage=300, stale-while-revalidate=60 header for CDN/browser caching.

How it works

  1. First request for a username → hits GitHub API, stores result in cache
  2. Subsequent requests within 5 minutes → served from cache (no API call)
  3. After TTL expires → next request fetches fresh data

Benefits

  • Reduces GitHub API rate limit consumption
  • Faster responses for repeated comparisons
  • Zero external dependencies (in-memory Map)

Test plan

  • Compare same usernames twice — second request should be noticeably faster
  • Wait 5+ minutes and compare again — should fetch fresh data
  • Check response headers include Cache-Control

Add in-memory cache with 5-minute TTL for GitHub GraphQL responses.
Duplicate requests for the same username are served from cache,
reducing API calls and improving response times.

- Add lib/cache.ts with generic get/set/stats helpers
- Wrap fetchGitHubUserData with cache lookup
- Add Cache-Control header to compare API response

Closes O2sa#33
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 11, 2026

@aoi-dev-0411 is attempting to deploy a commit to the osama's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

Thank you for the pull request! ✅

A maintainer will review this soon. Please be patient while we take a look. 🙌

@Ai-chan-0411
Copy link
Copy Markdown
Contributor Author

Hi @O2sa! Just checking in — this PR implements caching for GitHub API responses (closes #33). The implementation uses an in-memory cache with configurable TTL and automatic cleanup. Ready for review whenever you get a chance! 🙏

@Ai-chan-0411
Copy link
Copy Markdown
Contributor Author

Closing this PR as there has been no maintainer feedback for several weeks. Thank you for the opportunity to contribute! Feel free to reopen if you would like these changes.

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.

Implement caching for GitHub API responses

1 participant