Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache to function response #22

Merged
merged 4 commits into from
Jul 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ module.exports = async (req, res) => {

const stats = await fetchStats(username);

res.setHeader('Cache-Control', 's-maxage=3600');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 5min cache would be good enough since we need the frequent updates too

res.setHeader("Cache-Control", "public, max-age=300");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, similar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 minutes would be good I guess, I made it one hour just to test it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! magic number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, good catch, I can move it into a constant or something.

const FIVE_MINUTES = 300;
res.setHeader('Cache-Control', `public, max-age=${FIVE_MINUTES}`);

Copy link

@dikshantpatodia dikshantpatodia Jul 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a constants file under src, add all the constants there -> export -> tada

For the const, instead of FIVE_MINUTES we can name it like MAX_AGE_LIMIT_IN_MS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I commented that to Anurag, but he said he wanted to add that to env so it can easily be changed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

res.setHeader("Content-Type", "image/svg+xml");
res.send(
renderSVG(stats, {
Expand Down