Skip to content

Commit af77820

Browse files
authored
feat: Add env variable for optionally disabling cache feature (#879)
1 parent f4b600e commit af77820

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
# replace ghp_example with your GitHub PAT token
1+
# replace ghp_example with your GitHub PAT token (see README for instructions)
22
TOKEN=ghp_example
3+
4+
# optional: Add a comma-separated list of GitHub usernames to whitelist (only these users' streaks will be displayed)
5+
# WHITELIST=DenverCoder1
6+
7+
# optional: disable caching (not recommended, may cause rate limit issues)
8+
# DISABLE_CACHE=true

src/index.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@
4646
"exclude_days" => $excludeDaysRaw,
4747
];
4848

49-
// Check for cached stats first (24 hour cache)
50-
$cachedStats = getCachedStats($user, $cacheOptions);
49+
// Check if cache is disabled
50+
$useCache = !isset($_SERVER["DISABLE_CACHE"]) || strtolower($_SERVER["DISABLE_CACHE"]) !== "true";
51+
52+
// Check for cached stats first (24 hour cache) unless cache is disabled
53+
$cachedStats = $useCache ? getCachedStats($user, $cacheOptions) : null;
5154

5255
if ($cachedStats !== null) {
5356
// Use cached stats - instant response!
@@ -65,8 +68,10 @@
6568
$stats = getContributionStats($contributions, $excludeDays);
6669
}
6770

68-
// Cache the stats for 24 hours
69-
setCachedStats($user, $cacheOptions, $stats);
71+
// Cache the stats for 24 hours unless cache is disabled
72+
if ($useCache) {
73+
setCachedStats($user, $cacheOptions, $stats);
74+
}
7075
}
7176

7277
renderOutput($stats);

0 commit comments

Comments
 (0)