freistilbox adds support for Cache Tags
Published 2019-03-14 by geewiz
A Varnish proxy cache speeds up content delivery by orders of magnitude and has been part of our managed hosting platform since we started in 2010. By storing content in RAM, Varnish saves your web application from having to execute expensive rendering processes for each and every incoming request. However, cache objects have an expiry time, which can cause Varnish to deliver stale versions of content that has since been updated in the application.
Delivering popular content speedily should not come with the downside of delivering updated content late; web applications need to be able to refresh cache objects as soon as the original content gets updated. That’s why we’ve improved our caching logic by adding support for Cache Tags.
The use of Cache Tags is a method that assigns labels to cache objects which the application can use to easily invalidate all cache objects with a certain label. Let’s take as an example an article that also has a number of graphical assets like diagrams and photos. The moment you update the article, a whole number of cache objects might become stale:
- the article text,
- one or more graphical assets,
- the home page (if it contains a link with the article title),
- multiple link list pages (e.g. a monthly archive or a topic list)
With the simple cache purge mechanism freistilbox offered before, you had to either invalidate each of these cache objects individually or wait until they expired by themselves. Both alternatives were not optimal.
The new Cache Tags support in freistilbox allows your web application to assign a common tag to the article, each of its assets and all the other places where it is mentioned. Now, when you update the article, your web application can instruct Varnish with a single HTTP request to invalidate all cache objects carrying this tag in one fell swoop.
On the technical level, this works by delivering your content with a HTTP header like
Cache-Tags: reports,report-march-2019. When asked to invalidate the tag
report-march-2019, Varnish will immediately mark all cache objects that carried this Cache Tag as outdated, regardless of their expiry time.
Integrating Cache Tags in web applications built with Drupal is easy thanks to the Purge and Varnish Purger modules. Our user documentation explains all the details. (freistilbox supports Cache Tags with WordPress, too, but we haven’t seen a plugin supporting them yet.)
Go ahead and try it out! Your website visitors will appreciate getting both your new and your updated content hot off the press.