Skip to content

feat: Add File-based Caching#862

Merged
DenverCoder1 merged 7 commits intoDenverCoder1:mainfrom
ironashram:coolify
Feb 7, 2026
Merged

feat: Add File-based Caching#862
DenverCoder1 merged 7 commits intoDenverCoder1:mainfrom
ironashram:coolify

Conversation

@ironashram
Copy link
Contributor

@ironashram ironashram commented Dec 23, 2025

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.php now 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

  • New feature (added a non-breaking change which adds functionality)

How Has This Been Tested?

  • Tested locally with a valid username
  • Deployed successfully to my Coolify instance

Checklist:

  • I have checked to make sure no other pull requests are open for this issue
  • The code is properly formatted and is consistent with the existing code style
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Copy link
Owner

@DenverCoder1 DenverCoder1 left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for working on this!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@ironashram
Copy link
Contributor Author

@DenverCoder1 pushed some changes to address the comments, thanks

@DenverCoder1 DenverCoder1 temporarily deployed to streak-stats-coolify-xxurec5qe February 7, 2026 20:38 Inactive
Copy link
Owner

@DenverCoder1 DenverCoder1 left a comment

Choose a reason for hiding this comment

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

Thanks so much! This should definitely improve the response time 🎉

@DenverCoder1 DenverCoder1 merged commit f4b600e into DenverCoder1:main Feb 7, 2026
4 checks passed
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.

3 participants