TechAtNYU / tech-nyu-site

https://techatnyu.org
8 stars 5 forks source link

Cloudflare caching #58

Open ethanresnick opened 9 years ago

ethanresnick commented 9 years ago

prompted by @thebyrd's comment about cloudflare caching:

  1. can we ping cloudflare when we redeploy to invalidate its cache?
  2. just more generally, can we control the cloudflare ttl? we need to think about this for the updating event on our homepage
thebyrd commented 9 years ago
  1. Yes
  2. Yes, I've made it 4 days, but can change that for you. If you're only updating html for each event, probs ok to make it 1 day?
ethanresnick commented 9 years ago

Cool.

Re 2. Sometimes we get our events into the system pretty last minute, like ~6 hours before (not ideal, but hey). Also, during Startup Week, where we can have one event right after another, we kinda need the page to update in near-real time. So, if we had to pick one time that would cover the SW case too, we'd probably want something really aggressive, like every 15 minutes. Is that an option on whatever free tier we're using? If not, that goes to the next point...

Re 1. How do we set that up?

thebyrd commented 9 years ago
  1. There's an API I'll cook up a bash script for you
  2. You guys are on the bowery business plan, so you can do all of this. I'd rather keep the TTL long and then just purge every time you deploy. Since people don't use the website that frequently, you loose a lot of the benefits of the cache if everything expires every 6 hours.
thebyrd commented 9 years ago

This repo is public and it involved an API secret, so I'll send it to you and Abhi in slack. Don't show it to anyone. It's a simple curl statement.

ethanresnick commented 9 years ago

@thebyrd Thanks David!

Keeping the TTL long and then purging only when necessary makes sense. I think that means purging in two cases:

  1. On deploy, purge everything. That's something that Abhi can easily add to the githook. I made an issue for that.
  2. Every time the contents of http://api.tnyu.org/v1.0/up-next-publicly change. Since the site is already polling that url to get the next event, it can pretty easily keep track of whether the next upcoming event has changed, and then alert cloudflare. But, when it does that, it only needs to clear cloudflare's cache of the html file, not the css or js. Is there an easy way to do that?

Alternatively, will cloudflare just respect our headers? Because the ideal scenario would be to treat it just like any other cache, rather than having to special case it. That is, we could tell cloudflare to check our site every fifteen minutes, but we'll send the with an etag that only changes when we redeploy or the next event changes. So we'd just send cloudflare a 304 if their cache is still good. And we could do the same thing for the static files.

ethanresnick commented 9 years ago

Fuck. Moving to Cloudflare broke all our subdomains again, so I had to temporarily switch the nameservers back to namecheap.

@thebyrd can you make sure cloudflare is reflecting all our other dns records properly (see below/in the namecheap control panel) before switching back

screen shot 2015-03-03 at 6 09 23 pm

thebyrd commented 9 years ago

:fire: :fire:

adding a subdomain in cloudflare is pretty straightforward. A slack message would have solved the problem in 5 minutes. Now the site is down, when you're ready to get the site back up, please slack me the subdomains and ips you'd like.

Next time you don't know how something works don't freak out in ignorance. Instead, communicate.

abhiagar commented 9 years ago

Don't keep switching dns please! Breaks a lot of things during events @ethanresnick

On Tuesday, March 3, 2015, David Byrd notifications@github.com wrote:

[image: :fire:] [image: :fire:]

adding a subdomain in cloudflare is pretty straightforward. A slack message would have solved the problem in 5 minutes. Now the site is down, when you're ready to get the site back up, please slack me the subdomains and ips you'd like.

— Reply to this email directly or view it on GitHub https://github.com/TechAtNYU/tech-nyu-site/issues/58#issuecomment-77072602 .

thebyrd commented 9 years ago

I haven't touched it yet

ethanresnick commented 9 years ago

@thebyrd You're right that I could have asked you first, and then only made the change on my own if you didn't respond right away. I just felt a sense of urgency because I got a message from the bd team telling me that they were sending out sponsorship prospectuses and companies couldn't get them to load, so I reacted in a bit of a panic. I do appreciate your help with this.

@AbhiAgarwal Sorry that this broke stuff during the event! I just wanted to get the things back online for bd asap.