At FatLab, within our web hosting offering, we provide our clients with several types of caching to aid in website performance.
What is Website Caching
Caching is where we save a web page to memory so that it can be retrieved quicker than if the server has to process each request.
Processing a web page is difficult, especially when working with a CMS like WordPress. Each time a visitor to your site requests a page, a series of events needs to happen, and each of these takes time.
Now granted, we are talking milliseconds here, but they add up, and the final result is that a site visitor could be waiting several seconds, or worse, many seconds, for a web page to render within their browser fully.
What Happens When a Web Page is Requested
In a super simplistic mode, when a user requests a page from a website, the following things have to happen:
- The request has to be recognized, but the server
- A look-up has to be done to see if what is being requested is available on the server. Assuming that the request is a good one and the server does have the requested resources, then the real work begins.
- The server will begin to process the page, going through each line of markup.
- Some stuff will be sent directly to the browser, such as HTML and text.
- Some stuff will require that database queries be run; this may pull images, text, and more markup, all of this then needs to be processed, and the results must be sent to the user’s browser.
A single web page could have hundreds if not thousands of things; it must process before the user receives everything they need to see a web page.
Each of those has to be downloaded by the user and processed by their browser. Some of these might not even be hosted on the same server, and therefore the user’s browser now must make connections to multiple servers all over the globe to render a single web page.
Caching to the Rescue
To speed this up, we use caching. So instead of making the server work so hard for every request, caching is s method by which we run this process once and then save the results to memory.
Caching to the Rescue: TLDR
So, in short, caching allows us to run the slower process of putting the whole web page together and sending it to the visitor’s browser only once; then, for future requests, send an already processed copy from memory…. Fast.
How Typical Caching Works (WordPress)
This is where the processed page is stored in memory for super quick retrieval without having to do all that stuff I described above. There are several technologies used for this, such as Memcache or Varnish.
This is where a processed page is stored on the hard drive as HTML, ready to be sent to the user (or to server-level caching) when requested.
Page Caching and Server-Level Caching Working Together
These typically work in tandem. In the case of WordPress, a plugin will typically create the page cache before a user even requests it; this way, it is already processed and sitting there wing to jump into action when requested.
Server-level caching then holds copies of these pages after they have been requested.
There is also some cool stuff that goes on here; for example, at the server level, caching is managed by the server’s memory, so it holds the most requested pages and may drop a seldom requested page from memory.
This means it is constantly cycling the cached pages for the most efficiency. Popular pages are quick, while less popular pages may take just a few milliseconds longer. The more traffic a site gets, the more efficient this becomes.
The Advantages of Website Caching
The advantages should be clear now; the server doesn’t have to work as hard to create a webpage and send it to the visitor’s browser, so it loads more quickly.
A quicker web page keeps your attention on a website, and Google and other search engines even reward faster sites/pages with higher rankings.
A faster website feels better to the end user, we are an impatient species, and the smoothness of a fast-loading website cannot be denied.
The Challenges Website Caching
Can you see the problem here? I just told you that we process the page once and save it to memory and then send that over and over and over again.
But what if the content changed? The power of using a CMS like WordPress is that it allows website owners to change content quickly.
What good is it if you change content, important content, and the server is still sending out old copies of a web page without the latest/greatest content? It’s not good at all, and in fact, it can be very frustrating. We call this a “stale” cache.
Clear the Cache, Duh… Maybe
The obvious answer to the challenge is to clear the cache, but that might not be as easy as it sounds. Above, I mentioned that we often use more than one type of caching; this means a copy of any web page may reside in multiple places, meaning they all have to be cleared.
In the case of page caching in WordPress, the page cache is typically cleared each and every time a page is saved, then there are (or should be) processes in place that send a signal to the server-level caching to also clear that same page from memory so it can be reprocessed. This isn’t always the case, though, and it’s frustrating when content does not seem to update.
There are also situations, like news posts, for example, where even if caching is working on the individual post, meaning the system clears all caches each time it is updated, that same news post may be listed in multiple places on the website.
For example, a home page with a section called “Our Latest News” lists news posts. Changes to the individual post may not update the home page because it has its own cached copy.
Solving the Challenges of Caching
As someone who supports websites, I think it’s essential to educate clients on why we use caching.
Everyone seems obsessed with page speed these days and explaining that caching is a major part of performance usually justifies it.
However, that doesn’t always curtail the frustration when clients are making rapid changes to web pages, and people are reporting that they can’t see them.
As I stated earlier, caching will typically be cleared for each updated page, but it may not clear the cache for all pages in the site. This is typically solved by a function that allows the entire cache to be cleared manually… a button that sometimes literally says “clear cache.”
The catch here, of course, is that the site administrator must remember to push this button after making changes to the site, and this can be tough to do.
Wrapping it up
Caching is a great performance tool that helps improve the user expense of visitors to any site; it also aids in search engine rankings. However, there is a trade-off that may include extra steps for content administrators.