If you are reading this article with curiosity, you might have already come across the term ‘Cache’ or ‘Caching’. You might have heard about using Cache to speed up the website. And instances, where you need to clear your cache when your website is not responding properly.
In this article, I’ll discuss the following questions. What is Cache? What are the types of Cache? The advantages and disadvantages, and how to clear Cache on a WordPress site?
What is Cache?
A straightforward definition is that Cache is a static version of your web pages that are stored at the client or the server side. This static version helps to render the web content faster and present it to your visitors in no time.
How Does Cache work in WordPress?
When a user requests a WordPress web page (in simple words, accesses a WordPress website), the PHP compiles the code in the background and stores/retrieves the data from the database using MySQL queries. The data is then retrieved from the server in the form of HTML and is presented to the user.
This loop can be cut short if the previously generated data is a general content which will be requested by the user or by several users very often. The cache helps to store this data in the client’s browser or the server side, depending on where the caching is performed.
Hence, caching can be also defined as reusing the previously generated content to speed up future web page requests.
What are the Types of Cache?
Basically, there are three types of Cache with respect to WordPress:
- Client-side Cache
- Server-side Cache
- WordPress Plugin Cache
1. Client-side Cache
Also known as Browser Cache, these are fragments of data stored in the user’s web browser. When a user requests for a web page, the information is retrieved from the server and is presented to the user.
A copy of this data is stored in the user’s web browser in the form of Cache. When the user requests for the same information in the future, the information stored in Cache is presented to the user.
With this type of caching, the number of requests per page will reduce, hence saving considerable time for accessing the page multiple times.
But what if there is an update to the content?
When the content is updated, the user may not see the change immediately. This is because the cache still contains the old data and needs to request the server for the updated content. The process of updating the cache is called Purging the Cache. The old cache files are deleted and the new cache is generated with the updated content. In WordPress, the cache will be purged when a new post is published, an old post is updated, a comment is posted, etc.
When the user makes a web page request, the browser checks for the update in the form of ‘304 response code’. If there is no update, the response will be negative (no). Instead, ‘200 response code’ is made to use the Cached content.
2. Server-side Cache
Unlike client-side caching, server-side caching has several mechanisms involved.
a) Full page caching: At the server side, the HTML pages are divided or fragmented into small units in the form of headers, body content, footer and so on. When the page request is made, WordPress simply combines all the fragments and presents it to the user. This could be quite useful for WordPress sites that run WooCommerce stores, as the user can enter your site from a particular product page listed in the search results.
b) PHP Code recompilation: When the PHP compiled code is cached, the server saves the time and resource for recompiling the same code for the subsequent requests made by other users.
c) MySQL database query results: Everytime the PHP code executes, the data has to be stored or retrieved from the database, based on the MySQL query. With caching mechanism, the results of the executed query can be cached, and can be retrieved when the request is made.
d) Object caching: WordPress, by default, has an object caching API that is used to cache some programmatic objects. The object cache lasts only for the ongoing request.
The server-side caching mechanism is useful in sites with high web traffic, where a number of users are requesting for the same content.
When the web page is requested, the server caching mechanism combines all the HTML fragments with the previously compiled PHP result, the previously executed MySQL query result, and the associated objects. It then sends the response to the user in the HTML form as a complete, single page.
Some of the managed hosting providers, like WPEngine, have their own caching mechanism. If you are in a shared hosting service, the caching option is still available with limited advantage.
Also, different hosting services have their own way of enabling the cache.
- How to enable caching on Turbo Web Hosting?
- SuperCacher for Siteground hosting service.
- Installing Breeze plugin for WooCommerce caching.
3. WordPress Plugin Cache
WordPress plugin repository has plugins for every small customization for our site, including caching. Instead of the browser, the caching plugins generate cache data for your WordPress website.
Here are the top 3 WordPress caching plugins:
1) WP Super Cache
This plugin is developed by Automattic, the folks behind WordPress. The plugin offers to serve static HTML files to 99% of your website users. One thing that really caught my attention was that you can choose to not cache for some logged-in users. Based on the login status, custom cache can be generated.
In addition to caching, the plugin offers page compression, cache rebuild mechanism, and CDN support. You can even preload the post, categories, and tags. The plugin has over two million installs!
The plugin serves cache in three ways:
- Expert – The quickest method, requires technical knowledge to modify the .htaccess file of your WordPress website.
- Simple – The recommended method that does not require modification of the .htaccess file and rather provides ‘supercached’ files that keep parts of your page dynamic in the caching mode.
- WP-Cache caching – Most flexible option, but slower than the other two methods. This method is basically used for known (logged-in) users. This mode is always enabled and can be disabled as required.
2) WP Total Cache
WP Total Cache consists of a number of useful features resulting in over a million installs! It can cache search result pages, feeds, database and memory objects, minified/compressed website pages, blog post, scripts, and stylesheets.
Additionally, it also offers Accelerated Mobile Pages (AMP) support, Security Socket Layer (SSL) support and CDN integration to name a few. This plugin can be used for both shared hosting or dedicated server. The developers claim that it can improve your overall site performance by 10 times and can save up to 80% of your bandwidth. Why not try it yourself?
3) WP Fastest Cache
The third one on our list is the WP Fastest Cache plugin. It is one of the most simple yet effective caching plugins. In addition to creating static HTML pages, the plugin offers cache timeout options for specific pages, preload caching, excluding pages and users for caching, and leverage browsing option, multiple language support to name a few.
The plugin has easy options to enable/disable caching for mobile devices and logged-in users. You can also disable emojis on your site.
It has over 600,000+ installs and has been one of the fastest growing caching plugins because of its offerings.
A special mention to Breeze plugin by Cloudways. The plugin combines performance, convenience, and simplicity in one powerful package. It is one of the useful plugins for your WordPress, WooCommerce or WordPress multi-site setup, and has the potential to grow faster.
Alternate Caching Technique
While most of the WordPress plugins offer the minifying process, you can do this at server or client as well.
Advantages of using Cache
- During the course of the article, you already have noticed that in every step cache saves a lot of time. This is very useful if you are in shared web hosting.
- Caching helps in improving responsiveness of the website, in turn, helping your site achieving better Page Rank in the Search Engine Results Pages (SERPs).
- Less number of compilations and query executions means faster loading time and saving server memory.
- It is one of the key components in optimizing your WordPress site.
- Since static cache pages are smaller in size compared to their dynamic pages, it saves user’s bandwidth although by a fraction amount.
Disadvantages of using Cache
- The capacity of the cache memory is very low. Hence, data more than the available capacity cannot be stored.
- Too much of cache data can make the primary memory response slower.
How to effectively clear WordPress Cache?
There are three ways to clear cache with respect to WordPress:
- Clearing Cache in Browser
- WordPress Caching Plugins
1. Clearing Cache in Browser
This is a very common method to clear the cache. Every browser settings contain quick option to clear the cache data.
Following demonstration shows how to clear cache in different browsers:
For Google Chrome:
- Open Google Chrome and click on the menu (three vertical dot icon) on the top right corner of the browser.
- Next, click More Tools to reveal further settings and click on Clear browsing data… option, as shown in the screenshot below.
- A pop-up window appears where you can check the data to be cleared. By default, Cached images and files option is checked. Finally, click on CLEAR DATA button to clear the cache data, as shown in the below screenshot.
For Mozilla Firefox:
- Open Mozilla Firefox and click on the menu (breadcrumb icon) on the top right corner of the browser.
- Click Options setting as shown in the screenshot below.
- Next, click on Privacy and Security tab and scroll down to Cookies and Site Data settings. Click on Clear Data button, as shown in the below screenshot.
- A pop-up window appears where you need to choose the type of data to be cleared. Tick the Cached Web Content checkbox and click on the Clear button to clear Cache data from your Mozilla Firefox browser, as shown in the screenshot below.
For Opera browser, read how to empty Cache in the Opera Help section.
For Safari, read How to clear Safari’s cache and cookies on Mac?
2. WordPress Caching Plugins
Follow the below steps to clear cache for the WordPress Caching plugins discussed in the earlier section of this article.
1) How to clear cache using WP Super Cache?
- Go to Settings option in the WordPress admin menu and click on WP Super Cache.
- In the Easy tab settings, scroll down to find Delete Cached Pages settings.
- Finally, click on Delete Cache button.
A sample screenshot of the WP Super Cache settings is shown below.
2) How to clear the cache using W3 Total Cache?
- Click on Performance option in the WordPress admin menu to reach the plugin dashboard section.
- Click on empty all cache to clear all cache, or if you want to clear other types of caches such as Memcached, opcode, disk cache, or want to update the media query string, click on the respective button.
Below is a sample screenshot of the W3 Total Cache settings.
3) How to clear the cache using WP Fastest Cache?
- Click on WP Fastest Cache setting in the WordPress admin menu.
- Next, move to Delete Cache tab and click on Delete Cache to delete all the cache data.
- Or you can click on Delete Cache and Minified CSS/JS to delete all cache data and minified stylesheet and script files.
A sample screenshot of the WP Fastest Cache settings is shown below.
A useful Add-on plugin: Clear Cache for Me
While the caching plugins that I mentioned above can clear most of the cache, there are chances that the cache in your site may not be completely cleared. Cache data for widgets, customizer, contact form 7, menus, settings, gallery albums, etc might be not cleared properly. Hence in such case, you can use an add-on plugin called Clear Cache for Me.
Over to you…
Caching helps in speeding up your WordPress website by creating static versions of the dynamic pages of your website. While caching can be one of the aspects to optimize your website, it has its own share of cons. If your site has lots of dynamic content, the cache has to be updated very frequently. In my opinion, always give first preference to getting a faster hosting service, rest everything falls.
Clear your web browser cache as the first step in clearing your cache data. If you are using WordPress plugins for caching, they provide straightforward steps for clearing any cache generated by the plugin or otherwise.
That’s all folks!
For now, continue exploring LearnWoo.