At Section we are occasionally asked if users should implement cache warming to increase the likelihood that their visitors will be served content from the cache and as a result speed up page load times. In this blog we want to go over the concept of a warm cache vs a cold cache and the benefits and downsides of warming your cache for visitors.
Warm Cache vs Cold Cache
As explained in our post on how web caching works, a cache, whether deployed on one local server or through a Content Delivery Network, stores a copy of the files that make up a webpage so they can be delivered to visitors more quickly. By caching copies of image files, CSS, and HTML documents, the origin server does not have to generate these files each time a new visitor comes to the website. This both improves page load time and decreases stress on the origin server, meaning a website can serve more visitors at once.
Because modern websites are constantly being updated - whether it’s a media site updating the articles on their homepage or an ecommerce site updating inventory of a certain product - files are set to expire after a set period of time, which may be a minute or an hour. Each time a file in the cache expires, it needs to be re-collected from the origin server.
The first visitor to visit a website after a cache is initially set up or a cache expires will go through an empty or cold cache and experience a “cache miss.” The cache will visit the origin server to retrieve the file, deliver it to the visitor and keep the file in the cache so it is then a full or warm cache. Each subsequent user that visits before the cache expires again will be served from cache - a “cache hit” for all files that have been stored.
To summarize, a cold cache is one that does not have any files stored in it, and a warm cache has files stored already and is prepared to serve visitors.
Cache Warming: Benefits and Drawbacks
Generally websites want visitors to encounter a warm cache so that they are served more quickly. However, unless sites engage in active cache warming, some visitors will encounter a cold cache after content expires or the cache is cleared.
So what is cache warming and how does it benefit websites? Cache warming is when websites artificially fill the cache so that real visitors will always get a cache hit. Essentially, sites that engage in cache warming are preparing the cache for visitors (hence the term “warming” as in the warm engine of a car), rather than allowing the first visitor to get a cache miss. This ensures every visitor has the same experience.
While it seems logical that websites would want all of their visitors to have a similarly fast page load time, the drawbacks of the practice can often outweigh its benefits. For one thing, the majority of websites will have more than one cache server or cache content through a globally distributed content delivery network, which could have hundreds of caches.
To have a completely warm cache, websites need to fill all of those caches. They can do this by using a crawler, but that crawler would have to hit the website multiple times and from multiple locations to ensure every cache is filled. This becomes increasingly complicated as the number of caching servers increases, and may unnecessarily increase load on the website since the caches must be filled regularly in anticipation of visitors coming to the site, even if actual visitors are not hitting the website before the cache expires.
Another issue arises when looking at websites with many pages, articles, or products. To fully warm a cache, these all would need to be cached regularly, even though some pages may be requested very infrequently. A website with 1000 products may only get visitors to 20 product pages, and by using real visitors to warm the cache rather than a crawler the visitors will dictate which items need to get cached often.
While cache warmers for systems including Magento and Wordpress are quite popular, we recommend sites that use Varnish Cache or another caching solution examine both the benefits and downfalls of using a cache warmer. For high-traffic sites, cache warming is not necessary as enough visitors are coming to fill the cache regularly, and for sites with many products cache warming can significantly increase server load.
In addition, websites should always aim to improve their performance using several methods rather than only through caching - with a fast connection time and front end optimizations in place, users will have a good on-site experience even if they reach a cold cache.