Fix and improve some caching in our views.
Review Request #7167 — Created April 5, 2015 and submitted — Latest diff uploaded
There were some areas where we weren't doing a great job of handling
caching or generating ETags. We also had a bug in a recent change that
prevented us from having reliable ETags.The recent addition of
TEMPLATE_SERIAL
didn't end up creating a stable
serial. The assumption the code made was that a call to
generate_ajax_serial()
would always re-calculate the proper value based
on the modified time of the templates, but this actually only happens
the first time. That meant that every timeinitialize()
was called, we'd
changeTEMPLATE_SERIAL
, making it unstable. We're a bit more careful
now to only set this once.We had some less-than-optimal ETags, which basically just exposed some
state, generating longer and longer ETags as we added to them. We now
compute a hash based on these values.We also had a couple cache checks based on the Last-Modified timestamp,
but this isn't a great thing to base caching off of. They're not
flexible, and they come with precision issues and can end up being
ignored based on other headers. We now use ETags instead.
Unit tests pass.
Verified that I got repeated 304s on these views, so long as the source of
the ETags did not change.This also fixed the odd little bug with the Review Request Last Update URL,
where every other request would return a 200 instead of a 304.