...

How to Use W3 Total Cache

how-to-use-w3-total-cache

Clear WordPres Cache

With over 1 million active installations, W3 Total Cache is one of the most popular ways to optimize and manage the cache for your WordPress site. This can result in faster load times and less strain on your server, which can also help your SEO (search engine optimization) efforts.

  • How to Optimize WordPress with W3 Total Cache
  • How to Clear WordPress Cache
  • How to Import or Export W3 Total Cache Settings

Learn how to improve WordPress performance with our NGINX-powered WordPress Hosting.

How to Optimize WordPress with W3 Total Cache

By default, WordPress is a dynamic CMS (Content Management System). This means that for every visitor request that WordPress has to process, it must first connect to the database to see if the requested page even exists.

In a lot of cases, this might not be problematic on a site that doesn’t receive much traffic. However, a sudden surge in traffic caused by search engine bots, or just a general increase in normal traffic can quickly cause your WordPress site to use up a lot of CPU resources from the server while trying to fulfill needless duplicate requests again and again.

You can counter this increase in CPU usage by implementing a caching plugin. What these do is cache the first visitor’s request of a new page to a plain HTML file on the server. Then, when another visitor comes through and requests the same page, so long as the page wasn’t updated in your administration section, or updated by a comment, the cached HTML page will be served.

This can greatly reduce CPU usage of your WordPress site very easily. As an example, let’s say you had 100 views of your front page. Without caching that would require the same database query to have to run 100 times, and every time it’s just getting back the exact same data anyway.

With a caching plugin, only the first user would have the database query run to generate the cached HTML file. Then, the next 99 visitors would get that cached HTML served to them right away, without having to wait for any database activity to complete.

This is just about always a win-win, because your visitors don’t have to wait as long for your pages to load, and you’re reducing the impact of WordPress’s requests on the server’s performance.

Please note that database caching is not recommended for Shared Hosting as this process is dependent on the disk speed of the server. Due to the nature of shared system resources, disk speed may be limited and as such database caching may adversely affect the performance of your site. We recommend experimenting with different caching techniques to see which works best for your site.

  1. Install the W3 Total Cache plugin by BoldGrid.
    Installing W3 Total Cache
  2. From the left-hand menu, you should now have a new Performance section. Hover over this and click on General Settings.
  3. Scroll down the general settings page ensuring that the following section is enabled. Then, click the  Save all settings button.
    Page Cache:
    Enabling Page Cache in WordPress
    Minify:
    Minify CSS and JS Files
    NOTE: If you are using minify, make sure to enable the option, save it and then immediately look at your WordPress site to make sure that the site looks normal. If you see problems with formatting, then it’s possible that a theme or plugin is causing issues due to the minification. You should then disable minification and not use this option with your website.

    Opcode Cache (in this example it was not available on my server):
    Enabling Opcode Cache
    Database Cache:
    Turn Database Caching on
    Object Cache:
    Turn Object Caching on
    Browser Cache:
    Turn Browser Caching On
    CDN (you must be subscribed to a 3rd party service):
    Enabling the CDN Option

  4. Hover over Performance again in the left-hand menu, and click on Page Cache.
  5. Ensure that these options have a checkmark beside them, then click on Save all settings:

    Cache front page
    Cache feeds: site, categories, tags, comments
    Cache SSL (HTTPS) requests
    Cache 404 (not found) pages
    Don’t cache pages for logged in users
    Don’t cache pages for following user roles (only use this if you want to disable cache for specific roles)
    Enable Page Cache

  6. Finally to confirm that you’ve set up everything correctly, in your web browser open up your site and hit (Ctrl-U), or go to View -> Page source to view the source of the page. Scroll to the very bottom of the page and you should see the W3 Total Cache banner letting you know the page has been optimized.
    W3 Total Cache Source

How to Clear WordPress Cache

Clearing your WordPress cache can be something you may need to do from time to time when using a caching plugin to speed up WordPress. If you make changes to your WordPress site and don’t see the changes when visiting the updated page, you may need to clear your cache. This is because the caching plugin could still be showing the cached version of your page.

To force your WordPress site to show your most recent changes right away, you can delete the cache. Below are steps to clear the WordPress cache in the Dashboard and via WP-CLI.

Clear Your Cache in the Dashboard

  1. Login to your WordPress Dashboard.
  2. Hover over Performance, then click Dashboard.
  3. Click the empty all caches button.
    Delete Server Cache

Clear Your Cache in WP-CLI

  1. Log in to SSH or cPanel Terminal.
  2. Navigate to your WordPress directory.
  3. (Optional) Ensure W3TC is installed and active: 
    wp plugin status w3-total-cache 

    You should receive the plugin name and Active status.

  4. To purge URLs within your content delivery network (CDN) and Varnish (if enabled): 
    wp w3-total-cache cdn_purge

  5. To flush other caches:
    wp w3-total-cache flush an-attribute-below
    all
    posts – page and posts cache
    post – page cache
    database
    object
    minify
    For example: 
    wp w3-total-cache flush all

How to Import or Export W3 Total Cache Settings

There may be times when you want to backup your settings or use them on a different site. Follow along and we’ll walk you through importing and exporting your W3 Total Cache settings in the Dashboard. We will then show you how to import a settings file via WP-CLI.

Import/Export Your Settings From the Dashboard

  1. Log in to your WordPress dashboard.
  2. Under Performance, select General Settings.
  3. At the bottom, export your settings by clicking the Download button.
    Download Cache Settings
  4. Import your settings by clicking the Choose File button to select your backup (.json) file. Then, click the Upload button.
    Upload Settings

Import Your Settings with WP-CLI

  1. Upload the file to your cPanel account.
  2. Log in to SSH or cPanel Terminal.
  3. Navigate to your WordPress directory.
  4. (Optional) Ensure you’re in the correct directory: 
    wp option get home && wp option get siteurl

    You should receive your domain twice.

  5. (Optional) Ensure W3TC is installed and active: 
    wp plugin status w3-total-cache

    You should receive the plugin name and Active status.

  6. Run this command: 
    wp w3-total-cache import file-path-to-filename

Discover more from WIREDGORILLA

Subscribe now to keep reading and get access to the full archive.

Continue reading