To improve the performance of your WordPress site, the Contextual Related Posts plugin offers two inbuilt caching options: Cache Posts only and Cache HTML output. This guide will walk you through enabling and configuring these settings.

Why Enable Caching?

Caching helps reduce the load on your database and speeds up the delivery of related posts to your users. By enabling caching, you ensure that your website runs efficiently, even under heavy traffic.

  • Cache Posts only allows you to cache the output of the main related posts query which subsequently reduces future page loads.
  • Cache HTML output is more aggressive as it caches the HTML generated for the related posts and thereby reduces all the queries needed to look up the posts, thumbnails, etc.

Enabling/disabling caching

Both settings are enabled by default to optimize the related posts out-of-the-box. You can toggle the settings by navigating to Settings > Related Posts and the Performance tab.

The Cache HTML output setting will supersede Cache Posts only and is recommended particularly on busy sites. This setting will not work with the Related Posts Query Loop Block and so it is recommended that you keep Cache Posts only enabled.

What is never served from the HTML cache

The HTML cache is shared by every visitor to a post, so output that is not the same for everyone is skipped. Contextual Related Posts bypasses the HTML cache when:

  • The visitor is logged in
  • The post is password-protected, or the visitor holds a password cookie for any post

These requests still generate related posts; they are built fresh and are not written to or read from the shared cache. Cache Posts only is unaffected, because it caches post IDs rather than rendered markup.

Clearing the cache

Contextual Related Posts caches all related posts for one week by default.

You can manually clear the plugin cache by visiting the Tools page and using the Clear Cache button. Contextual Related Posts Pro users also have a dedicated Clear cache button in the Settings page at the bottom.

The cache of a post is also cleared when it is edited. This is to ensure that the related posts are generated using the latest content.

You can also enable the Clear cache when a post is trashed or restored option in the Performance tab to automatically clear the entire cache whenever a post is moved to Trash or restored from Trash. This option is disabled by default.

Changing the caching duration

The duration of the cache can be modified by changing the constant CRP_CACHE_TIME, which is set to be one week by default. The easiest way to modify this constant is by setting it to a different period in your wp-config.php. e.g. the below will set it to a week using the inbuilt WordPress constant.

define( 'CRP_CACHE_TIME', WEEK_IN_SECONDS );

Was this article helpful?