Search

Invalidating the cache

Invalidating the cache

Welcome to chapter 6. Let’s kick this one off with a very powerful saying:

There’s only one thing worse than not caching enough, and that is caching for too long.

Allow us to elaborate.

The only detrimental effect of uncacheable content, or content with a low TTL, is a low hit rate. By now you should appreciate the direct impact of a good hit rate. Although latency or downtime are potential consequences of a poor hit rate, the alternative could be much worse.

If you cache for too long, the cached content might no longer represent the actual state of the origin content. Data inconsistency is the main effect, and in a lot of situations, that’s really bad.

Imagine the news industry: online newspapers heavily depend on caches to cope with traffic spikes. But when they have a scoop, the breaking news item should immediately be visible on their homepage.

But when a cache like Varnish is used, as long as the TTL hasn’t expired, the breaking news item is nowhere to be found.

The same applies to live video content delivery: the manifest files, which contain references to the video files, may change depending on what the camera records. For live events it is very important to have consistent content.

It is commonly believed that it’s not worth caching the manifest files because they often change, but in most cases it is not entirely true: manifest files can be cached for a short period of time as long as you have a cache invalidation plan to not evict outdated manifest files from the cache.

What’s the solution to this problem? Lowering your TTLs? No, not really, because it’s not a dilemma of having to choose between a high hit rate and data consistency.

There is a door number three, which is invalidating cached objects.

Varnish has various mechanisms to mark objects as expired or to forcefully remove objects from cache. Endpoints and interfaces are offered for external applications to trigger these invalidations.

When you look at plugins and integrations from popular open source content management and e-commerce frameworks like Drupal, WordPress, Magento, Joomla and Prestashop, you’ll see that their main focus is hooking into their content management logic and integrating endpoints to Varnish’s cache invalidation.

This chapter will focus on these mechanisms to remove objects from the cache. The main objectives being data consistency and freeing up space in the cache.


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203