Performancing Metrics

The Importance of Caching in WordPress

W3 Total Cache LogoI had a pretty rough night last month.

After relaxing for a bit with my wife, I checked my site only to find that it wasn’t there at all. Instead, I was greeted with an error message saying that WordPress could not connect to the database.

I logged into my server’s control panel and noticed that the server load was unfathomably high, much more than it could ever take. I’d been dealing with a weird CPU issue for a while so I restarted the server, expecting it to correct itself.

But when my server eventually restarted, the site came back but only for a second, it quickly went down again. Whatever was causing it wasn’t just a temporary issue.

I contacted my host, which told me that they were seeing very high levels of traffic to the server, more than it could handle. It turns out the article I had written about a recent plagiarism case on Reddit was getting some attention both via Reddit itself and Google searches. The volume just seemed too high.

But then I looked at the sample level of traffic that I managed to snag when the site came back up briefly. It was high, many times my normal level, but nothing the server shouldn’t be able to take easily. It had, in the past, handled spiked much bigger than this.

My host agreed and we worked together to keep the site offline but give me access. Once in, I realized that I had made a terrible mistake.

The week before, I had to, in an emergency, create a new theme for my site. As part of that I had disabled W3 Total Cache. While a great move at the time, when I was done I had forgotten to reenable it and the site was without any kind of caching.

I reenabled the plugin, checked that it was working and then opened the site back up to the rest of the world. Sure enough, though the load was high and the server was straining some, it was nowhere near buckling. The highly-elevated traffic remained for several days and, through it all, there wasn’t as much as a glitch or a hiccup.

If I had remembered to reenable W3 Total Cache, or any caching plugin, I probably wouldn’t have noticed the traffic spike until I checked the stats the next day and I certainly wouldn’t have people on Reddit commenting about how quickly my site went down.

It was an embarrassment that ended up being minor, but it serves as a reminder to every WordPress user: Make sure you are using a caching plugin.

Why Caching is Important

Most people don’t think about what happens behind the scenes every time someone visits a page, but your server does.

If you use WordPress, or any other similar content management system that doesn’t have caching, there are a series of steps that your server has to complete to go from page requested to page delivered.

Basically, without caching, when a visitor tried to load a page, the page itself doesn’t exist. Instead, the server receives the request, WordPress queries the database for the content that’s supposed to be in the page and builds the page on the fly before delivery. Once that visitor is gone or goes to another page, the page disappears and the process starts over again.

While this is an over-simplification, the main issue is that the server has to create the page every time someone looks at it. While this is great in that rapidly-changing pages are updated for each visitor, it’s a lot of work for a server and even a decent VPS, such as my own, can struggle under that if there are a lot of visitors coming at once.

A caching plugin, ont he other hand, keeps WordPress from having to create a new page every time. The page is created once and held onto (or cached) for a period of time, usually a few hours. Subsequent visitors to that page get the cached version, which prevents the server from having to check the database and assemble the page from scratch.

To the visitor, this is much faster and to the server, this is much easier.

To use a personal computer example. Imagine, if instead of using copy and paste, you had to retype a paragraph into a new document every time you wanted to repeat the text. Though retyping it lets you make changes to it as you go, copying and pasting is much easier and faster for you.

But as great as caching is, it’s something that’s frightfully easy to forget and the reason is very simple.

Why Caching is Easy to Forget

A lot of bloggers don’t see the need or importance of caching and it’s easy to see why. Caching is most useful when a lot of people are trying to load the same content. Most blogs don’t see the kind of traffic level where caching has a major impact one way or another.

For example, if a page your site only gets a visitor once or twice a day, then it probably is being loaded dynamically every visit, caching or no. The reason is that the cache, most likely, expires between visitors, forcing the creation of a new page.

On low-to-medium traffic sites, there are probably only a few pages that get enough traffic to regularly deliver cached content and, even then, it’s probably doesn’t adversely impact the server. A well-optimized server can serve a decent number of dynamic pages without a problem.

So while caching probably has at least some speed benefit, it’s usually one that’s difficult to notice, especially to the naked eye.

This prompts many bloggers to skip on caching or, in my case, forget to check if it’s working, because everything functions fine without it.

However, as my case showed, it can be a road to disaster.

When Caching Matters

One of the strange things about the Internet is that it has a way of quickly giving a lot of attention to something that had very little of it previously. Between social media such as Facebook and Twitter as well as social news sites like Reddit, a tidal wave of traffic can hit any site at any time.

These types of moments are what bloggers work for, an opportunity to reach a large audience and a chance to capitalize and maybe grow your reach long-term. However, you can’t do that if your site is down.

But it doesn’t make sense to buy and pay for hosting strong enough to survive those waves when 99% of the time you will only need a fraction of it. It’s like buying a huge bathtub to hold a glass of water, expensive and wasteful.

Instead, the best thing you can do is make sure your site is as efficient as possible so it can survive waves of traffic visiting the same page without trouble. Caching is the best way to do that.

So, if you don’t cache, you’re severely limiting the number of visitors your site can receive. While that may be fine most of the time, it basically shuts the door in the face of potential visitors who are coming to see you at your most popular.

Bottom Line

In the end, WordPress is a great CMS for many sites but its lack of caching means that it can easily overpower even decent servers quickly. Fortunately, a decent caching system is never more than a plugin away.

Truth be told, my reminder was not a particularly painful one, it could have been much worse. An hour or sporadic downtime could have turned into much longer since the site wasn’t “down” in a sense that my monitors would detect. It could have gone until the next morning before returning to normal.

However, I’m not going to let dumb luck be what helps me get my site back up. I’m going to make sure to always run a caching program and, though I’m certain I’ll have to disable it from time to time to do work, I’m going to make double sure to reenable it when done.

I don’t want to risk another Reddit wave shutting me down…

Categories: WordPress Plugins, WordPress Tips

This post was written by . You can visit the for a short bio, more posts, and other information about the author.

Comment with Your Facebook Account

Comments

  1. Shevonne ) says: 1/9/2013

    I agree. Caching is super important. I had that happen on my site as well, and I was stressing over how sluggish it was for weeks. I use Quick Cache and also the Amazon Web Services (AWS).

    Reply

  2. Steven Ramirez ) says: 1/9/2013

    Jonathan, I agree that generally caching is a good thing. Unfortunately for me, I just started using the AdRotate plugin and, according to the author, it doesn’t play well with caching programs. Specifically, the ads don’t rotate. So for now I am stuck with full-on live WP each time someone hits the site.

    Reply

  3. Malathy Badri ) says: 1/9/2013

    This is an excellent blog post. Very educative and a must read for bloggers. I have a question. Why did you have to disable the W3-total cache plugin while changing the theme? Is it a must? Thanks for your time.

    Reply

  4. Darnell Jackson ) says: 1/10/2013

    Good topic,

    I still think that the server should have the ability to handle the requests without the caching plugin. Many times these servers are shared and the combined processing is what’s causing the problem.

    A dedicated server would solve this problem also if the cost justify the upgrade.

    Reply

  5. Joe Hart says: 1/11/2013

    Such errors do happen…Without caching high loads of traffic cannot be managed..Glad that you resolved the issue.. :)

    Reply

  6. Dean Saliba ) says: 1/11/2013

    See I have tried many times to use a caching plugin like Super Cache and W3 Total Cache but every time I enable them my blog produces the dreaded white screen of death. My host runs on a Linux server so I have come to the conclusion that they don’t work on a Linux server. :(

    Reply

  7. Marius says: 1/21/2013

    Cashing is important, but care must be taken between cashing on your website and the cashing of the host. Only one should be switched on, otherwise you can end up with integrity problems.

    Reply

  8. Ray says: 1/27/2013

    W3 Total Cache is a great WordPress plugin. It has a lot of extra features, which is nice, but a little confusing too. I have read a lot of different suggestions about how to set it, and each one recommended something different. I know a lot of people have trouble setting it up. Super Cache is another good caching plugin. It’s much simpler to configure, but doesn’t have as many features. I use both on 2 different sites. Both have been decent for me.

    The only other drawback with a cache plugin is people don’t realize that they need to clear the cache if or when they make changes to things like themes or .css. They make a change refresh their page and wonder why they don’t see the changes. So I tell them don’t forget to clear the cache after making changes just in case.

    Anyway caching works great for me. My setup doesn’t support it, but I hear some people see even better results when combined with apc cache, eaccelerator, memcache, xcache, and things like that.

    Reply

  9. Taswir Haider says: 1/27/2013

    I agree. Caching is super important.The only other drawback with a cache plugin is people don’t realize that they need to clear the cache if or when they make changes to things like themes or .css. A dedicated server would solve this problem also if the cost justify the upgrade.

    Reply

  10. Bryan Haines ) says: 1/30/2013

    I agree with caching. Until I installed WP Super Cache, we were being billed overage charges every month by our hosting company. With the new plugin, the overages have stopped. Now if only I could figure out how to properly configure CloudFlare – every time I install it, it works for a couple of days and then completely screws up my email server and message get lost…

    Reply

  11. Lorenzo says: 3/20/2013

    Caching can definitely help speed up a site, especially if its running on shared hosting. One point though, if you are running an ecommerce store on WordPress, you’ll want to set your caching plugin to exclude the pages within the store.

    Reply

  12. SFP says: 5/22/2013

    it works for a couple of days and then completely screws up my email server and message get lost…

    Reply