Object Caching
Object caching involves storing database queries and, when enabled on your website, it can help speed up PHP execution times, reduce the load on your database, and deliver content to your visitors faster.
Storing database query results is helpful so that the next time a result is needed, it can be served from the cache without having to repeatedly query the database. Content management systems like WordPress are naturally — and heavily — dependent on the database. As such, database efficiency is crucial to scaling CMS-driven websites.
If you run a high-traffic site and requests to your pages generate a large number of database queries, your server can quickly become overwhelmed, in turn negatively affecting your site’s performance. So when object caching is enabled on your site, it can help ease the load on your database and server and deliver queries faster.
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.