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 purge step to CI deploy stage #533

Merged
merged 2 commits into from
Jun 16, 2021
Merged

Add cache purge step to CI deploy stage #533

merged 2 commits into from
Jun 16, 2021

Conversation

jb3
Copy link
Member

@jb3 jb3 commented Jun 15, 2021

I want to serve site from the edge, since the content there is primarily static. This PR ensures that cached content is cleared upon deploy so that we can benefit from high edge cache TTLs while still having new content deploy immediately.

Copy link
Contributor

@ToxicKidz ToxicKidz left a comment

Choose a reason for hiding this comment

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

Lgtm

Copy link

@jacobmonck jacobmonck left a comment

Choose a reason for hiding this comment

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

Joe is the best programmer in the world

@MarkKoz
Copy link
Member

MarkKoz commented Jun 15, 2021

Is there a smarter way to clear invalidated cache items rather than purging the whole thing? Not sure if that even make sense with the way they store cache, but I don't know how they do that.

@jb3 jb3 enabled auto-merge (squash) June 15, 2021 23:57
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling cf9d880 on jb3/cf-cache-purge into 865c2ed on main.

@jb3
Copy link
Member Author

jb3 commented Jun 16, 2021

Is there a smarter way to clear invalidated cache items rather than purging the whole thing? Not sure if that even make sense with the way they store cache, but I don't know how they do that.

@MarkKoz If you pay Cloudflare, you can pass a list of wildcards to invalidate. We could pass a list of individual file URLs but it's unnecessary complexity. It's better to just have pages have a slightly higher initial load time (which assets already do – considering we currently serve django pages with no cache other than for static assets).

Below graph shows HTTP reqs to our server from clients in US, HK & UK.

Start of graph is serving from our servers, so responses range from 300ms to 1.2s, so worst case scenario for each Cloudflare PoP that has no cached copy someones request takes up to that duration.

End of this graph shows serving from the Cloudflare PoPs, which makes site response times considerably faster, consistently sub-100ms.

image

@MarkKoz
Copy link
Member

MarkKoz commented Jun 16, 2021

It's better to just have pages have a slightly higher initial load time

Better in terms of what, just reduced complexity?

Anyway a max of 1.2s for a few unlucky people sounds acceptable.

@jb3
Copy link
Member Author

jb3 commented Jun 16, 2021

Better in terms of what, just reduced complexity?

Yeah, that's all. The process for conditional invalidation would be along the lines of getting a diff of files changed, mapping that to URLs and then pushing that to Cloudflare, it's possible but is another component to maintain. We'd need to build static assets, reverse all the resource and guide URLs and so on, which is possible but I'm not sure it's worth it.

@jb3 jb3 merged commit 297337f into main Jun 16, 2021
@jb3 jb3 deleted the jb3/cf-cache-purge branch June 16, 2021 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants