diff --git a/api/gist.js b/api/gist.js index 8821c7b0..5b03743c 100644 --- a/api/gist.js +++ b/api/gist.js @@ -42,32 +42,17 @@ export default async (req, res) => { const gistData = await fetchGist(id); let cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.SIX_HOURS, 10), - CONSTANTS.SIX_HOURS, - CONSTANTS.ONE_DAY, + parseInt(cache_seconds || CONSTANTS.TWO_DAY, 10), + CONSTANTS.TWO_DAY, + CONSTANTS.SIX_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 - and if both are zero we are not showing the stats - so we can just make the cache longer, since there is no need to frequent updates - */ - const stars = gistData.starsCount; - const forks = gistData.forksCount; - const isBothOver1K = stars > 1000 && forks > 1000; - const isBothUnder1 = stars < 1 && forks < 1; - if (!cache_seconds && (isBothOver1K || isBothUnder1)) { - cacheSeconds = CONSTANTS.SIX_HOURS; - } - res.setHeader( "Cache-Control", - `max-age=${ - cacheSeconds / 2 - }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, + `max-age=${cacheSeconds}, s-maxage=${cacheSeconds}`, ); return res.send( diff --git a/api/index.js b/api/index.js index 2029367c..9fde2d7e 100644 --- a/api/index.js +++ b/api/index.js @@ -79,8 +79,8 @@ export default async (req, res) => { let cacheSeconds = clampValue( parseInt(cache_seconds || CONSTANTS.CARD_CACHE_SECONDS, 10), - CONSTANTS.SIX_HOURS, - CONSTANTS.ONE_DAY, + CONSTANTS.TWELVE_HOURS, + CONSTANTS.TWO_DAY, ); cacheSeconds = process.env.CACHE_SECONDS ? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds diff --git a/api/pin.js b/api/pin.js index 0bc029d7..bede7d87 100644 --- a/api/pin.js +++ b/api/pin.js @@ -57,32 +57,17 @@ export default async (req, res) => { const repoData = await fetchRepo(username, repo); let cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.CARD_CACHE_SECONDS, 10), - CONSTANTS.SIX_HOURS, + parseInt(cache_seconds || CONSTANTS.PIN_CARD_CACHE_SECONDS, 10), CONSTANTS.ONE_DAY, + CONSTANTS.TEN_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 - and if both are zero we are not showing the stats - so we can just make the cache longer, since there is no need to frequent updates - */ - const stars = repoData.starCount; - const forks = repoData.forkCount; - const isBothOver1K = stars > 1000 && forks > 1000; - const isBothUnder1 = stars < 1 && forks < 1; - if (!cache_seconds && (isBothOver1K || isBothUnder1)) { - cacheSeconds = CONSTANTS.SIX_HOURS; - } - res.setHeader( "Cache-Control", - `max-age=${ - cacheSeconds / 2 - }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, + `max-age=${cacheSeconds}, s-maxage=${cacheSeconds}`, ); return res.send( diff --git a/api/top-langs.js b/api/top-langs.js index 382ee420..d1815559 100644 --- a/api/top-langs.js +++ b/api/top-langs.js @@ -70,10 +70,9 @@ export default async (req, res) => { count_weight, ); - let cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.CARD_CACHE_SECONDS, 10), - CONSTANTS.SIX_HOURS, - CONSTANTS.ONE_DAY, + let cacheSeconds = parseInt( + cache_seconds || CONSTANTS.TOP_LANGS_CACHE_SECONDS, + 10, ); cacheSeconds = process.env.CACHE_SECONDS ? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds @@ -81,9 +80,7 @@ export default async (req, res) => { res.setHeader( "Cache-Control", - `max-age=${ - cacheSeconds / 2 - }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, + `max-age=${cacheSeconds / 2}, s-maxage=${cacheSeconds}`, ); return res.send( diff --git a/api/wakatime.js b/api/wakatime.js index de263e06..73ef9986 100644 --- a/api/wakatime.js +++ b/api/wakatime.js @@ -54,7 +54,7 @@ export default async (req, res) => { let cacheSeconds = clampValue( parseInt(cache_seconds || CONSTANTS.CARD_CACHE_SECONDS, 10), CONSTANTS.SIX_HOURS, - CONSTANTS.ONE_DAY, + CONSTANTS.TWO_DAY, ); cacheSeconds = process.env.CACHE_SECONDS ? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds diff --git a/src/common/utils.js b/src/common/utils.js index 48ea0517..b780657c 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -449,7 +449,11 @@ const TWO_HOURS = 7200; const FOUR_HOURS = 14400; const SIX_HOURS = 21600; const EIGHT_HOURS = 28800; +const TWELVE_HOURS = 43200; const ONE_DAY = 86400; +const TWO_DAY = ONE_DAY * 2; +const SIX_DAY = ONE_DAY * 6; +const TEN_DAY = ONE_DAY * 10; const CONSTANTS = { ONE_MINUTE, @@ -461,8 +465,14 @@ const CONSTANTS = { FOUR_HOURS, SIX_HOURS, EIGHT_HOURS, + TWELVE_HOURS, ONE_DAY, - CARD_CACHE_SECONDS: SIX_HOURS, + TWO_DAY, + SIX_DAY, + TEN_DAY, + CARD_CACHE_SECONDS: ONE_DAY, + TOP_LANGS_CACHE_SECONDS: SIX_DAY, + PIN_CARD_CACHE_SECONDS: TEN_DAY, ERROR_CACHE_SECONDS: TEN_MINUTES, };