When does WP-Optimize clear the page cache?

Full cache purge:

  • When changing/updating current themes and parent themes (of child themes)
  • When changing/updating current plugins
  • When turning off the cache feature in WP-Optimize
  • When editing widgets
  • When saving the customizer settings
  • When updating a menu
  • When Autoptimize purges its cache
  • When updating permalink structure
  • When changing cache settings
  • When updating string translations in WPML plugin
  • When updating the ‘posts_per_page’ option
  • When purging Avada theme’s fusion caches
  • When saving any of GetWooPlugins’ settings (Premium)

This can be changed by hooking into the filter wpo_purge_cache_hooks. E.g.

// Add a new action that will trigger a cache purge
add_filter( 'wpo_purge_cache_hooks', function( $actions ) {
    $actions[] = 'my_custom_action';
    return $actions;
} );

Partial cache purge:

  • When you publish new content or update/edit existing content, the cache for that post/page will be cleared, as well as associated content (category archives, blog archives)
  • When comments are approved, or their status changes
  • When terms are created or updated
  • When changing/updating stock quantity of WooCommerce product or product variation
  • When updating the ‘page_on_front’ option
  • When updating ‘page_for_posts’ option
  • When updating the ‘URLs to exclude from caching’ WP-Optimize caching configuration
  • When trashing a post
  • When running importers
  • When WooCommerce product is on sale (Premium)

 

Does the WP-Optimize page cache work with non-pretty (query parameter-based) permalinks?

No. It’s necessary to have pretty permalinks of the type http://xxxxx.com/my-post/ rather than http://xxxxx.com/?p=1234. Pretty permalinks are the WordPress default setting, and there is no good reason to turn them off, so you should not have a problem with this.

Note that permalinks including /index.php/ are cacheable. It is only those based upon query parameters (?…) that are not.

How do I know my webpage is being cached (or why it isn’t)?

Make sure you are getting the page from the webserver (rather than from your browser cache) by emptying your browser cache and reloading the page. Do this whilst logged out (because the default setting is not to serve cached pages for logged-in users, since logged-in users usually want live content). Then, use the “View Source” function in your web browser to view the page source. Scroll down to the bottom, and you should see a line added by the cache:

HTML source showing that the page was served from the cache

However, note that if you are using a further service that minifies HTML (e.g. Cloudflare), then this line may have been removed. Another method is to inspect the contents of the directory wpo-cache inside your wp-content directory.

If your page is not being served from the cache, and you want to find out why not, then firstly – are you sure it is not being so served? As just mentioned, minification will remove HTML comments, like the line above. If you are sure, then you should edit your wp-config.php file, and change the WP_DEBUG setting to true, like so:

define('WP_DEBUG', true);

Then, reload the page, and view the HTML source. The reason will be given at the bottom – if it is not being removed by minification. If you need to first turn off minification, then do so.

HTML comment showing why the page was not served from the cache