feat: Add File-based Caching#862
Conversation
…expiration Signed-off-by: Michele Palazzi <[email protected]>
…ctions Signed-off-by: Michele Palazzi <[email protected]>
Signed-off-by: Michele Palazzi <[email protected]>
DenverCoder1
left a comment
There was a problem hiding this comment.
Looks great, thanks for working on this!
There was a problem hiding this comment.
Pull request overview
This pull request introduces a file-based caching system to improve performance by reducing GitHub API calls. The cache stores GitHub contribution stats on disk with a 24-hour TTL, resulting in significant performance improvements (from ~4s to <100ms for cached requests). The implementation adds a new cache.php module with cache management functions, integrates caching logic into index.php, updates the Docker configuration to create and set appropriate permissions for the cache directory, and adds the cache directory to .gitignore.
Changes:
- Added file-based caching system (
src/cache.php) with 24-hour TTL to cache contribution stats - Modified request handler (
src/index.php) to check cache before making GitHub API calls - Updated HTTP cache headers from 3 hours to 24 hours to align with file cache duration
- Modified Dockerfile to create cache directory with appropriate permissions
- Updated .gitignore to exclude cache directory from version control
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
| src/cache.php | New module implementing file-based caching with functions for cache key generation, read/write operations, expiration handling, and cache cleanup utilities |
| src/index.php | Integrated caching logic to check for cached stats before GitHub API calls, with cache key generation based on user and request parameters (starting_year, mode, exclude_days) |
| Dockerfile | Added cache directory creation with 775 permissions for www-data user |
| .gitignore | Added cache/ directory to exclude cached files from version control |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Michele Palazzi <[email protected]>
Signed-off-by: Michele Palazzi <[email protected]>
Signed-off-by: Michele Palazzi <[email protected]>
|
@DenverCoder1 pushed some changes to address the comments, thanks |
DenverCoder1
left a comment
There was a problem hiding this comment.
Thanks so much! This should definitely improve the response time 🎉
Description
This PR adds a simple file based caching mechanism, i've been battling slowness and timeouts for a very long time while using this project in my gh profile and this has made a huge impact.
In my testing i've gone from around 4s for each request to under 100ms (after the first one gets cached obviously). This is currently deployed and used in my own profile with a self hosted Coolify instance.
The existing Dockerfile now creates a cache directory with appropriate permissions for the Apache www-data user. No breaking changes to the current container setup.
File-based caching system is defined in a new module (
src/cache.php) that persists contribution stats to disk, reducing GitHub API calls significantly. The cache uses a 24-hour TTL by default, generates unique keys via SHA256 hashes of request parameters, and handles errors gracefully so caching failures never break actual requests.Request handler integration in
index.phpnow checks for cached stats before hitting the GitHub API. Cache keys account for all relevant request parameters including starting_year, mode, and exclude_days. The HTTP cache headers were also updated from 3 hours to 24 hours to match the file cache duration.This is extremely beneficial in selfhosted docker scenario, i am not sure it would make any difference in Vercel since storage may not be persistent, anyway it should not break that kind of deployment or have any impact.
Fixes #
Type of change
How Has This Been Tested?
Checklist: