Skip to content

Commit

Permalink
feat: improve caching behavoir
Browse files Browse the repository at this point in the history
This commit ensures that both the private browser and shared CND caches are
used. By doing this, the load on both the Vercel instance, the GraphQL
and WakaAPI is reduced. In addition, the `stale-while-revalidate` option
was added to speed up the card loading.
  • Loading branch information
rickstaa committed Oct 4, 2022
1 parent aae83cb commit 677096c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default async (req, res) => {
CONSTANTS.ONE_DAY,
);

res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.setHeader("Cache-Control", `max-age=${cacheSeconds}, s-maxage=${cacheSeconds} stale-while-revalidate`);

return res.send(
renderStatsCard(stats, {
Expand Down
2 changes: 1 addition & 1 deletion api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default async (req, res) => {
cacheSeconds = CONSTANTS.FOUR_HOURS;
}

res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.setHeader("Cache-Control", `max-age=${cacheSeconds}, s-maxage=${cacheSeconds} stale-while-revalidate`);

return res.send(
renderRepoCard(repoData, {
Expand Down
2 changes: 1 addition & 1 deletion api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default async (req, res) => {
CONSTANTS.ONE_DAY,
);

res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.setHeader("Cache-Control", `max-age=${cacheSeconds}, s-maxage=${cacheSeconds} stale-while-revalidate`);

return res.send(
renderTopLanguages(topLangs, {
Expand Down
2 changes: 1 addition & 1 deletion api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default async (req, res) => {
cacheSeconds = CONSTANTS.FOUR_HOURS;
}

res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.setHeader("Cache-Control", `max-age=${cacheSeconds}, s-maxage=${cacheSeconds} stale-while-revalidate`);

return res.send(
renderWakatimeCard(stats, {
Expand Down

0 comments on commit 677096c

Please sign in to comment.