No matter how fast your server is, it is always a good idea to use different caching methods. It is important to understand how caching plugins work before you decide what is best solution for you based on how your website works and how much you want to gain with caching.
There are many cache plugins for WordPress. Some are only for a specific cache related use, and some implement all caching methods. If you want to use only a specific caching method, best solution is to get specialized plugin, if you need more – go with all in one solutions. Here on Dev4Press, cache is controlled by W3 Total Cache. Before we go into specific caching methods, there are some server features that can be used and that you may consider installing.
Why do you need to use cache?
Well, most important thing is speed. With one or more cache methods used, your website will be faster without expanding and upgrading the server. Faster website means that your visitors will get to information quicker, and slow websites are known to lose visitors that don’t want to wait long time for page to load. Also, search engines are taking website loading speed into account.
So, using cache will have some impact on the search engine rankings, will save you money on upgrading server and will improve visitors interaction.
This is general purpose solution that is made to work across multiple servers for distributed storage of cached data. Data is stored in memory, and oldest values will be removed if allocated memory runs out. This is a good solution if you need to use multiple servers with a lot of memory and the servers are within the same network.
There are several different accelerators available but most popular solutions are: APC, XCache and eAccelerator. They are storing compiled byte-code of PHP scripts into the memory. Normally, every time a script is executed PHP loads it and and compiles it. If you use accelerator, PHP runs pre-compiled byte-code from memory eliminating overhead of recompiling on each request. Here are some test results for loading of WordPress 3.3 with 3 different accelerators in use.
As you can see, use of accelerator for PHP will improve speed about 3 times. Accelerators can run on their own regardless of the cache plugin you decide to use, and you can’t use more than one accelerator in the same time. One more thing that accelerators can do is to work as object storage, and you can cache data also using functions.
This is the most popular caching method available, and the method that brings biggest speed improvements. Normally, when page is requested, server loads WordPress and everything else needed, code is compiled and executed. So, for each request server needs to load PHP, to load all required files and compile and execute all. Depending on the server power this can take a different amount of resources and time to complete. If you use accelerators on the server this can be faster due to storing of compiled code. But, you can save even more.
Cache plugin is changing how the page is loaded. When a page is rendered with PHP and you get HTML to output to the browser, cache plugin saves that output as a plain HTML file. Files are stored in the folders that mimic the permalinks structure. Each file is stored as HTML and GZIPPED HTML (well, this depends on the plugin you use). Cache plugins need to modify HTACCESS, and add new rewrite rules. These rules check if the user is logged in and if it is not (checked through cookie), HTML file is loaded. So, when cached page is loaded PHP is not used at all and WordPress is not loaded! User gets simple HTML content from a single file and that is it.
Typical gain in speed with page cache can be up to 10 times over normal non cache loading. Combined with some PHP Accelerator (for logged in users), you will get much faster loading. Accelerators have no impact on speed of page cache, since cached pages are HTML only.
CDN: Content Delivery Network
Very important thing to speed up your website is to have some of the files loaded from some other server. If you have 20 images, JS and CSS files loaded for each page, you can set up CDN network that will allow you to have only main HTML file loaded from your server, while all other files loaded from CDN server. There are different methods to this, but must common one is called Mirror. You set up your CDN server (there are many companies offering this service), and you set up CNAME record on your server to point to the CDN server.
But, process of changing URL’s can be very complicated, so cache plugins can do that for you automatically. With all plugins this is very easy to set up, and it depends on the CDN service you are using. CDN is not a free service, but the money you invest in this will pay off since you will save on your own server expanding, and you will have much faster website for your visitors.
Cache used on Dev4Press website
With all the cache optimizations active a home page on Dev4Press.com (according to Pingdom Full Page Test) loads for 0.857 seconds for 71 requests and 660KB of page size. Without any of the optimizations, home page takes 17.5 seconds to load. That is 2042% gain, or 20 times faster with cache!
There are more cache methods available, but in my experience objects or database cache are not worth using due to problems it can cause and marginal speed gains.
How much you will gain with different cache methods depends on many things including server speed and configuration, use of CDN, cache plugin(s) you use… In some cases you can’t use all cache methods, and it is best to experiment until you find what works best for you. There are many plugins available, different CDN services to use. I hope that this article will help you understand how some of the cache methods work to decide what to use.