Skip to content

Commit 3e66189

Browse files
authored
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
1 parent 38c8a7a commit 3e66189

File tree

5 files changed

+60
-20
lines changed

5 files changed

+60
-20
lines changed

api/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ export default async (req, res) => {
5555
parseArray(exclude_repo),
5656
);
5757

58-
const cacheSeconds = clampValue(
58+
let cacheSeconds = clampValue(
5959
parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10),
6060
CONSTANTS.FOUR_HOURS,
6161
CONSTANTS.ONE_DAY,
6262
);
63+
cacheSeconds = process.env.CACHE_SECONDS
64+
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
65+
: cacheSeconds;
6366

6467
res.setHeader(
6568
"Cache-Control",

api/pin.js

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export default async (req, res) => {
4444
CONSTANTS.FOUR_HOURS,
4545
CONSTANTS.ONE_DAY,
4646
);
47+
cacheSeconds = process.env.CACHE_SECONDS
48+
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
49+
: cacheSeconds;
4750

4851
/*
4952
if star count & fork count is over 1k then we are kFormating the text

api/top-langs.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ export default async (req, res) => {
6262
count_weight,
6363
);
6464

65-
const cacheSeconds = clampValue(
65+
let cacheSeconds = clampValue(
6666
parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10),
6767
CONSTANTS.FOUR_HOURS,
6868
CONSTANTS.ONE_DAY,
6969
);
70+
cacheSeconds = process.env.CACHE_SECONDS
71+
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
72+
: cacheSeconds;
7073

7174
res.setHeader(
7275
"Cache-Control",

api/wakatime.js

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export default async (req, res) => {
4646
CONSTANTS.FOUR_HOURS,
4747
CONSTANTS.ONE_DAY,
4848
);
49+
cacheSeconds = process.env.CACHE_SECONDS
50+
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
51+
: cacheSeconds;
4952

5053
if (!cache_seconds) {
5154
cacheSeconds = CONSTANTS.FOUR_HOURS;

readme.md

+46-18
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,44 @@ Please visit [this link](https://give.do/fundraisers/stand-beside-the-victims-of
8181

8282
</p>
8383

84-
# Features
85-
86-
- [GitHub Stats Card](#github-stats-card)
87-
- [GitHub Extra Pins](#github-extra-pins)
88-
- [Top Languages Card](#top-languages-card)
89-
- [Wakatime Week Stats](#wakatime-week-stats)
90-
- [Themes](#themes)
91-
- [Responsive Card Theme](#responsive-card-theme)
92-
- [Customization](#customization)
93-
- [Common Options](#common-options)
94-
- [Stats Card Exclusive Options](#stats-card-exclusive-options)
95-
- [Repo Card Exclusive Options](#repo-card-exclusive-options)
96-
- [Language Card Exclusive Options](#language-card-exclusive-options)
97-
- [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options)
98-
- [Deploy Yourself](#deploy-on-your-own)
99-
- [On Vercel](#on-vercel)
100-
- [On other platforms](#on-other-platforms)
101-
- [Keep your fork up to date](#keep-your-fork-up-to-date)
84+
85+
# Features <!-- omit in toc -->
86+
87+
- [GitHub Stats Card](#github-stats-card)
88+
- [Hiding individual stats](#hiding-individual-stats)
89+
- [Showing icons](#showing-icons)
90+
- [Themes](#themes)
91+
- [Customization](#customization)
92+
- [GitHub Extra Pins](#github-extra-pins)
93+
- [Usage](#usage)
94+
- [Demo](#demo)
95+
- [Top Languages Card](#top-languages-card)
96+
- [Usage](#usage-1)
97+
- [Language stats algorithm](#language-stats-algorithm)
98+
- [Exclude individual repositories](#exclude-individual-repositories)
99+
- [Hide individual languages](#hide-individual-languages)
100+
- [Show more languages](#show-more-languages)
101+
- [Compact Language Card Layout](#compact-language-card-layout)
102+
- [Donut Chart Language Card Layout](#donut-chart-language-card-layout)
103+
- [Donut Vertical Chart Language Card Layout](#donut-vertical-chart-language-card-layout)
104+
- [Pie Chart Language Card Layout](#pie-chart-language-card-layout)
105+
- [Hide Progress Bars](#hide-progress-bars)
106+
- [Demo](#demo-1)
107+
- [Wakatime Week Stats](#wakatime-week-stats)
108+
- [Demo](#demo-2)
109+
- [All Demos](#all-demos)
110+
- [Quick Tip (Align The Repo Cards)](#quick-tip-align-the-repo-cards)
111+
- [Deploy on your own](#deploy-on-your-own)
112+
- [On Vercel](#on-vercel)
113+
- [On other platforms](#on-other-platforms)
114+
- [Disable rate limit protections](#disable-rate-limit-protections)
115+
- [Keep your fork up to date](#keep-your-fork-up-to-date)
116+
- [:sparkling\_heart: Support the project](#sparkling_heart-support-the-project)
117+
118+
# Important Notice <!-- omit in toc -->
119+
120+
> **Warning**
121+
> 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).
102122
103123
# GitHub Stats Card
104124

@@ -623,6 +643,14 @@ Since the GitHub API only allows 5k requests per hour, my `https://github-readme
623643
5. You're done 🎉
624644
</details>
625645

646+
### Disable rate limit protections
647+
648+
Github Readme Stats contains several Vercel environment variables that can be used to remove the rate limit protections:
649+
650+
- `CACHE_SECONDS`: This environment variable takes precedence over our cache minimum and maximum values and can circumvent these values for self Hosted Vercel instances.
651+
652+
See [the Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables) on adding these environment variables to your Vercel instance.
653+
626654
### Keep your fork up to date
627655

628656
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.

0 commit comments

Comments
 (0)