Skip to content

Commit

Permalink
feat: add CACHE_SECONDS environment variable (#2266)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rickstaa authored Jun 9, 2023
1 parent 38c8a7a commit 3e66189
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 deletions.
5 changes: 4 additions & 1 deletion api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
64 changes: 46 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3e66189

Please sign in to comment.