Skip to main content

Caching can be overrated

Caching is something that always comes up to speed up your site. People see it as a requirement to have and trust fully on it to be working. The main issue I have with this is the fact that it doesn’t solve problems but simply hides them. People never look deeper into the issue to see if they can make the code itself more performant.

Complexity

When managing your sites one of the things you try to prevent is adding complexity. Adding caching is a way of adding complexity to your site. In WordPress the following ways are the most commons ones:

  • Object cache: No database manipulations any more, or you need to flush things yourself.
  • PHP Page cache: Always invalidate pages on all kinds of use cases. Also with a low traffic site this could slow things down
  • Varnish/Nginx Page cache: Adds even more complexity due to a different system caching things. This should only be done on high traffic sites.

By adding these complexities, it will result that the site needs to perform more actions which slows down certain request. So when your site doesn’t get a lot of traffic or a lot of traffic to all kind of pages it could mean a slower site. The chance of that is more likely then you would think. I do have to note that it all depends on your caching strategy. Doing things in memory is likely to be faster then on disk.

Choose the right software

This site runs on Nginx Mainline, PHP 7 and MariaDB 10.1. Due to running the latest software, my site is still really fast without any caching. I do have Redis as an object cache and batcache as a page cache. Due to the 5 minutes expiration time, I’m not that worried for invalidation since 5 minutes is still low enough to prevent weirdness in seeing old and new data through the site. And when it will be an issue, I can always change the values really fast. It also runs on two webservers with a loadbalancer in front. So it slows down a little bit but I now should be able to serve more requests.

The Hardware

The right software can only run a good as the hardware it’s using. The most easiest for us to see is if a host is using SSDs or not. If you ever switched the harddrive on your laptop to SSD then you can relate to the “sudden” speed increase. But it also makes a difference how things are set up. Do they use RAID and what is the setup. Obviously the processor makes a difference but I have to admit here that it’s hard to say. There are so many difference kinds that the even the GHz/cores doesn’t always tell the story. And then it’s the whole infrastructure how everything is build. I use Digital Ocean and the price/quality is really good.

This site

For a long period this site hasn’t had any caching plugins enabled due to the fact that a lot of module still aren’t released for PHP 7. So you need to compile it yourself. Also I’m using PHP 7 through dotdeb.org when it was still in beta. The problem in the beginning was that you weren’t able to install php-dev which allows you to compile PHP modules yourself. My sites didn’t really saw any slowdown due to the fact that I choose my software right. Also I wrote most of the code myself which resulted in almost no overhead.

I may have cheated a bit by changing the opcache configuration like to stop revalidation of files. This does add complexity since when you change a PHP file, you do need to reload PHP to flush the cache. The trade off here isn’t that high since it’s something I do or build scripts for.

Conclusion

I’m sure that I wouldn’t have wrote this post if it wasn’t of the great work the PHP and MySQL/MariaDB community has done in making their software as good as it is now. With PHP 7, MySQL 5.7 and MariaDB 10.1 the speed increase will be notable for you to see. This in combination with Nginx Mainline with HTTP/2 support means a fast site even when you don’t use caching.

But on the other side, I would still have written a similar post. A site’s main focus should be to display the content and not do things like getting information. As example, showing the most recent tweets on your site. You can request them and cache them in WordPress for a certain amount of time. But a better solution would be to have a microservice running that gets the tweets and stores them in the database. This could be a separate thing but could also be a WP-CLI command running as a cron. Personally I wouldn’t go for the WordPress cronjob.

So look at your site and see where you can make changes to make your site faster when not using any caching plugins.

One Reply to “Caching can be overrated”

  1. Marsha -

    “The main issue I have with this is the fact that it doesn’t solve problems but simply hides them.” Yes!! I totally agree. I find it especially irritating when website hosts recommend caching plugins to cover up bad server performance.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *