feat: add CACHE_SECONDS environment variable (#2266)

* feat: add CACHE_SECONDS environment variable

This commit adds the CACHE_SECONDS environment variable. This variable
can be used to circumvent our cache clamping values for self hosted
Vercel instances.

* refactor: apply formatter
This commit is contained in:
Rick Staa 2023-06-09 03:44:42 +02:00 committed by GitHub
parent 38c8a7a1e4
commit 3e66189c44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 19 deletions

View file

@ -55,11 +55,14 @@ export default async (req, res) => {
parseArray(exclude_repo),
);
const cacheSeconds = clampValue(
let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10),
CONSTANTS.FOUR_HOURS,
CONSTANTS.ONE_DAY,
);
cacheSeconds = process.env.CACHE_SECONDS
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
: cacheSeconds;
res.setHeader(
"Cache-Control",

View file

@ -44,6 +44,9 @@ export default async (req, res) => {
CONSTANTS.FOUR_HOURS,
CONSTANTS.ONE_DAY,
);
cacheSeconds = process.env.CACHE_SECONDS
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
: cacheSeconds;
/*
if star count & fork count is over 1k then we are kFormating the text

View file

@ -62,11 +62,14 @@ export default async (req, res) => {
count_weight,
);
const cacheSeconds = clampValue(
let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10),
CONSTANTS.FOUR_HOURS,
CONSTANTS.ONE_DAY,
);
cacheSeconds = process.env.CACHE_SECONDS
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
: cacheSeconds;
res.setHeader(
"Cache-Control",

View file

@ -46,6 +46,9 @@ export default async (req, res) => {
CONSTANTS.FOUR_HOURS,
CONSTANTS.ONE_DAY,
);
cacheSeconds = process.env.CACHE_SECONDS
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
: cacheSeconds;
if (!cache_seconds) {
cacheSeconds = CONSTANTS.FOUR_HOURS;

View file

@ -81,24 +81,44 @@ Please visit [this link](https://give.do/fundraisers/stand-beside-the-victims-of
</p>
# Features
- [GitHub Stats Card](#github-stats-card)
- [GitHub Extra Pins](#github-extra-pins)
- [Top Languages Card](#top-languages-card)
- [Wakatime Week Stats](#wakatime-week-stats)
- [Themes](#themes)
- [Responsive Card Theme](#responsive-card-theme)
- [Customization](#customization)
- [Common Options](#common-options)
- [Stats Card Exclusive Options](#stats-card-exclusive-options)
- [Repo Card Exclusive Options](#repo-card-exclusive-options)
- [Language Card Exclusive Options](#language-card-exclusive-options)
- [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options)
- [Deploy Yourself](#deploy-on-your-own)
- [On Vercel](#on-vercel)
- [On other platforms](#on-other-platforms)
- [Keep your fork up to date](#keep-your-fork-up-to-date)
# Features <!-- omit in toc -->
- [GitHub Stats Card](#github-stats-card)
- [Hiding individual stats](#hiding-individual-stats)
- [Showing icons](#showing-icons)
- [Themes](#themes)
- [Customization](#customization)
- [GitHub Extra Pins](#github-extra-pins)
- [Usage](#usage)
- [Demo](#demo)
- [Top Languages Card](#top-languages-card)
- [Usage](#usage-1)
- [Language stats algorithm](#language-stats-algorithm)
- [Exclude individual repositories](#exclude-individual-repositories)
- [Hide individual languages](#hide-individual-languages)
- [Show more languages](#show-more-languages)
- [Compact Language Card Layout](#compact-language-card-layout)
- [Donut Chart Language Card Layout](#donut-chart-language-card-layout)
- [Donut Vertical Chart Language Card Layout](#donut-vertical-chart-language-card-layout)
- [Pie Chart Language Card Layout](#pie-chart-language-card-layout)
- [Hide Progress Bars](#hide-progress-bars)
- [Demo](#demo-1)
- [Wakatime Week Stats](#wakatime-week-stats)
- [Demo](#demo-2)
- [All Demos](#all-demos)
- [Quick Tip (Align The Repo Cards)](#quick-tip-align-the-repo-cards)
- [Deploy on your own](#deploy-on-your-own)
- [On Vercel](#on-vercel)
- [On other platforms](#on-other-platforms)
- [Disable rate limit protections](#disable-rate-limit-protections)
- [Keep your fork up to date](#keep-your-fork-up-to-date)
- [:sparkling\_heart: Support the project](#sparkling_heart-support-the-project)
# Important Notice <!-- omit in toc -->
> **Warning**
> Since the GitHub API only [allows 5k requests per hour per user account](https://docs.github.com/en/graphql/overview/resource-limitations), the public Vercel instance hosted on `https://github-readme-stats.vercel.app/api` could possibly hit the rate limiter (see #1471). We use caching to prevent this from happening (see https://github.com/anuraghazra/github-readme-stats#common-options). You can turn off these rate limit protections by deploying [your own Vercel instance](#disable-rate-limit-protections).
# GitHub Stats Card
@ -623,6 +643,14 @@ Since the GitHub API only allows 5k requests per hour, my `https://github-readme
5. You're done 🎉
</details>
### Disable rate limit protections
Github Readme Stats contains several Vercel environment variables that can be used to remove the rate limit protections:
- `CACHE_SECONDS`: This environment variable takes precedence over our cache minimum and maximum values and can circumvent these values for self Hosted Vercel instances.
See [the Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables) on adding these environment variables to your Vercel instance.
### Keep your fork up to date
You can keep your fork, and thus your private Vercel instance up to date with the upstream using GitHub's [Sync Fork button](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork). You can also use the [pull](https://github.com/wei/pull) package created by [@wei](https://github.com/wei) to automate this process.