Website caching is one of the most beneficial technologies available. In short, it makes websites extremely fast, which leads to better SEO scores and increased user satisfaction — not to mention better conversions and therefore increased income if you’re selling products or services online.
Instead of processing every request, the server takes the results of these requests and stores them. It then serves these saved results instead — making everything much faster.
You may have come across the terms ‘object cache’ and ‘page cache’. These are both server caching methods — the full page cache is more basic because it’s an all or nothing approach, but it’s still very effective.
Object caching store only bits and pieces of data, as opposed to a full page. This can be useful within your code, and when storing the result of complex operations such as the generation of a navigation menu.
Websites are generally viewed hundreds, thousands, or sometimes even millions of times per month. Normally, each time a browser requests a web page, the server has to do a bunch of complex (and time consuming) calculations. It retrieves the latest posts, generates the header and footer, finds your site’s sidebar widgets, and so on. However, in many cases, the result of all these calculations will be exactly the same. Wouldn’t it be great, then, if we could simply make the server remember the final result, instead of processing each request separately? This is exactly what caching does!
It’s easiest to understand the caching process by looking at how a page is served. Let’s say you own a blog with caching enabled. The first time someone visits your homepage they receive the page in the normal way: The request is received, processed on the server, and the resulting web page to be shown is turned into an HTML file and sent to the visitor’s web browser.
Since caching is turned on, the server stores this HTML file — usually within its ‘random access memory’ (or RAM), which is extremely fast. The next time you, or anyone else, views the homepage, the server doesn’t need to do the processing and conversion to HTML. Instead, it simply sends the already prepared HTML file to the browser.
That all sounds great, but what if you have caching turned on and then publish a new post? Won’t the new post be outside of the cache and therefore invisible to site visitors? Well, all properly set up caching systems can deal with such scenarios. A caching system doesn’t just consist of the mechanism to store prepared HTML files, it also has a way to empty the cache (and then regenerate it) when specific conditions (such as the publishing of new content) are met.