fix: increase cache

This commit is contained in:
Anurag Hazra 2020-08-13 19:26:42 +05:30 committed by GitHub
parent 8fed801977
commit ec246d27ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 13 deletions

View file

@ -42,8 +42,8 @@ module.exports = async (req, res) => {
} }
const cacheSeconds = clampValue( const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.THIRTY_MINUTES, 10), parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.THIRTY_MINUTES, CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY CONSTANTS.ONE_DAY
); );

View file

@ -32,8 +32,8 @@ module.exports = async (req, res) => {
} }
let cacheSeconds = clampValue( let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.THIRTY_MINUTES, 10), parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.THIRTY_MINUTES, CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY CONSTANTS.ONE_DAY
); );
@ -47,7 +47,7 @@ module.exports = async (req, res) => {
const isBothOver1K = stars > 1000 && forks > 1000; const isBothOver1K = stars > 1000 && forks > 1000;
const isBothUnder1 = stars < 1 && forks < 1; const isBothUnder1 = stars < 1 && forks < 1;
if (!cache_seconds && (isBothOver1K || isBothUnder1)) { if (!cache_seconds && (isBothOver1K || isBothUnder1)) {
cacheSeconds = CONSTANTS.TWO_HOURS; cacheSeconds = CONSTANTS.FOUR_HOURS;
} }
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`); res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);

View file

@ -34,8 +34,8 @@ module.exports = async (req, res) => {
} }
const cacheSeconds = clampValue( const cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.THIRTY_MINUTES, 10), parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.THIRTY_MINUTES, CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY CONSTANTS.ONE_DAY
); );

View file

@ -139,7 +139,7 @@ You can provide multiple comma saperated values in bg_color option to render a g
&bg_color=DEG,COLOR1,COLRO2,COLOR3...COLOR10 &bg_color=DEG,COLOR1,COLRO2,COLOR3...COLOR10
``` ```
> Note on cache: Repo cards have default cache of 30mins (1800 seconds) if the fork count & star count is less than 1k otherwise it's 2hours (7200). Also note that cache is clamped to minimum of 30min and maximum of 24hours > Note on cache: Repo cards have default cache of 4hours (14400 seconds) if the fork count & star count is less than 1k otherwise it's 2hours (7200). Also note that cache is clamped to minimum of 2hours and maximum of 24hours
#### Stats Card Exclusive Options: #### Stats Card Exclusive Options:

View file

@ -167,6 +167,7 @@ const logger =
const CONSTANTS = { const CONSTANTS = {
THIRTY_MINUTES: 1800, THIRTY_MINUTES: 1800,
TWO_HOURS: 7200, TWO_HOURS: 7200,
FOUR_HOURS: 14400,
ONE_DAY: 86400, ONE_DAY: 86400,
}; };

View file

@ -143,17 +143,17 @@ describe("Test /api/", () => {
expect(res.setHeader.mock.calls).toEqual([ expect(res.setHeader.mock.calls).toEqual([
["Content-Type", "image/svg+xml"], ["Content-Type", "image/svg+xml"],
["Cache-Control", `public, max-age=${CONSTANTS.THIRTY_MINUTES}`], ["Cache-Control", `public, max-age=${CONSTANTS.TWO_HOURS}`],
]); ]);
}); });
it("should set proper cache", async () => { it("should set proper cache", async () => {
const { req, res } = faker({ cache_seconds: 2000 }, data); const { req, res } = faker({ cache_seconds: 8000 }, data);
await api(req, res); await api(req, res);
expect(res.setHeader.mock.calls).toEqual([ expect(res.setHeader.mock.calls).toEqual([
["Content-Type", "image/svg+xml"], ["Content-Type", "image/svg+xml"],
["Cache-Control", `public, max-age=${2000}`], ["Cache-Control", `public, max-age=${8000}`],
]); ]);
}); });
@ -175,7 +175,7 @@ describe("Test /api/", () => {
expect(res.setHeader.mock.calls).toEqual([ expect(res.setHeader.mock.calls).toEqual([
["Content-Type", "image/svg+xml"], ["Content-Type", "image/svg+xml"],
["Cache-Control", `public, max-age=${CONSTANTS.THIRTY_MINUTES}`], ["Cache-Control", `public, max-age=${CONSTANTS.TWO_HOURS}`],
]); ]);
} }
@ -185,7 +185,7 @@ describe("Test /api/", () => {
expect(res.setHeader.mock.calls).toEqual([ expect(res.setHeader.mock.calls).toEqual([
["Content-Type", "image/svg+xml"], ["Content-Type", "image/svg+xml"],
["Cache-Control", `public, max-age=${CONSTANTS.THIRTY_MINUTES}`], ["Cache-Control", `public, max-age=${CONSTANTS.TWO_HOURS}`],
]); ]);
} }
}); });