It’s nice to see that you’ve read my boring old article on WordPress’ Internal Functioning – kudos! Wait, what? You haven’t? No worries, just give it a quick read – especially the part under “What happens when someone views your WordPress blog?”.
As the title suggests, we’re going to learn WordPress caching. In this post series we’ll explore each aspect of caching one by one, in detail.
- Why it is important
- How does it work
- And finally, how to implement it.
Why is WordPress Caching so Important?
In college when they teach me a topic I know nothing about, I tend to think about its applications first, rather than learning about the topic. For example – recurrence relations. They’re used to calculate the nth number of a sequence of numbers, like the Fibonacci sequence. Once I understood its importance – how recurrence relations help save a lot of precious computation time – well, I took an interest in it. If you’d like to know a bit about recurrence relations, you’re in luck – I’m going to describe it briefly in the next paragraph. Folks who don’t wanna learn about it, could skip it – I wouldn’t mind. :P
A Fibonacci sequence is simply the addition of the previous two numbers in the sequence. Almost everyone from a Computer Science background know what I’m talking about – you’re bound to write a program (in any language) to generate a Fibonacci sequence. If I’m to start from 0, then the Fibonacci sequence would go:
0, 1, 1, 2, 3, 5, 8.. up to infinity.
Now from the above sequence, if I were to ask you the 5th number of the series, the answer would be 3. Now if I were to ask you the 500th number, you’d have to calculate the entire series up till the 500th term. For a modern computer, heck, your phone would compute it in less than a second. But, in terms of the modern processor, that’s a lot! Increase that 500 to 50,000,000,000 (50 billion-th) Fibonacci number and yeah – you’d need a lot more time.
This is where the recurrence relation comes in. Applying recurrence relations, we derive a formula that can calculate the nth Fibonacci term. Be it 5th or the 50th or the 50 trillion-th Fibonacci term, that derived formula can calculate all of them in exactly the same amount time, i.e. a constant time. This is incredibly helpful as it saves a lot of precious computation time and it also helps us calculate the complexity of a program.
So what’s this big fuss about WordPress caching?
Google loves faster sites. All of us love faster sites. One of Google’s key SERP (Search Engine Results Page) ranking factors include the speed of a website and its response time.
Caching is a fundamental factor in determining a site’s overall performance. Especially in WordPress, since it generates HTML pages dynamically – by employing PHP code coupled with MySQL database queries. With properly configured caching protocols your WordPress site can be orders of magnitude faster. It helps prevent redundancy and speeds up load times of your site – for free! Speeding up your WordPress site can be employed in 3 primary ways:
- Use high end, insanely powerful, clustered servers
- Use a Content Delivery Network (CDN)
- Configure WordPress Caching
The first two points can be (very) expensive and usually depend on the number of visitors a site has. However, WordPress caching can be used (and should be used) even in the smallest of websites. It’s interesting to know that the biggest name in WordPress Managed Hosting – WPEngine use their own custom built, proprietary caching technology called EverCache which combines all three major forms of caching – page, database and object caching.
What is WordPress Caching?
If you’ve read my previous article, you’ll know the number of stuff that takes place every time someone visits your site. Here’s an image to jog your memory:
What if those dynamically generated web pages were saved in the server’s hard disk or memory (RAM) and served from there, every time someone requested the page? Be it one or 1000 people, that same page would be sent! That would save a lot of database queries, PHP code execution, thereby saving the most important factor – precious computation time. It would be really, really fast.
This is WordPress caching. Reusing previously generated data (or requests such as database queries) to speed up new, subsequent requests.
But hang on, what if someone comments or updates a post or publishes a new one? Won’t those previously generated HTML pages contain the wrong/outdated data? You’re right, it absolutely would! Thus we have something called:
Purging the cache
Purging the cache essentially means re-caching all previously cached data. This means the old ones are are deleted and new ones are created or regenerated. This typically takes place based on a number of protocols – some of which include:
- When a comment is posted
- When a new post is published
- When an old post is updated
The WordPress core and the caching plugins know when to purge the cache so that old, irrelevant data isn’t served to the visitor.
This topic covers the two factors I find is important to understand before we begin to learn WordPress caching. Now that you have a solid understanding of the two, it is time to learn how caching works.
Benefits of WordPress Caching
To conclude this chapter, let’s take a look at some of the benefits caching has to offer:
- Speed up your site for free
- Thereby improving Google and other search engine rankings
- Save a substantial amount of the server’s resource consumption – very helpful for people who host their site in shared hosting servers
What are your thoughts on WordPress Caching? Do you have something to add to its list of benefits? Let us know in the comments section below!