Back to Community

How to Control WP-Optimize Cache Purging When Publishing or Editing Content

32 threads Sep 16, 2025

Content

One of the most common points of discussion for users of the 'WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance' plugin is its automatic cache purging behavior. Users often want the cache to update automatically when they publish new content, but the plugin's default settings can sometimes be too aggressive or not aggressive enough, leading to outdated content or unnecessary full cache clears.

Understanding the Default Behavior

By default, the plugin is designed to automatically purge the cache for a specific post or page when it is published or updated. It should also clear associated content like category and tag archives. However, based on user reports, this behavior can be inconsistent. Some users find the cache is not cleared at all for new content, while others report that editing a simple draft triggers a full site cache purge, which can be counterproductive for site performance.

Common Solutions and Code Snippets

Since the plugin's interface does not offer granular controls for these specific purging behaviors, the most common solutions involve adding custom code to your theme's functions.php file or using a code snippets plugin.

1. Force Purge on All Post/Page Updates

If your new or edited content is not appearing until you manually clear the cache, you can force a full purge on any update. This is a broad solution but ensures content is always fresh.

add_filter( 'wpo_purge_all_cache_on_update', '__return_true' );

2. Purge Cache Only When a Post is Published

To avoid purging the cache every time a post is edited or saved as a draft, you can use a more targeted filter that only triggers a purge when a post's status is changed to 'publish'. This is useful for news sites that publish content frequently.

add_filter('wpo_purge_all_cache_on_update', function($purge, $post_id) {
   if (get_post_status($post_id) === 'publish') {
       $purge = true;
   }
   return $purge;
}, 10, 2);

3. Set a Custom Cache Lifespan

For sites that update data very frequently (e.g., every 15-20 minutes), the hourly cache lifespan options in the UI may not be sufficient. You can use a filter to set the lifespan in seconds. Remember to reactivate the plugin or clear the cron event for this to take effect.

add_filter('wpo_option_key_page_cache_length', 'my_prefix_page_cache_length');
function my_prefix_page_cache_length() {
  return 60 * 15; // 15 minutes in seconds
}

Important Considerations

  • Testing: Always test code snippets on a staging site before implementing them on your live website.
  • Child Theme: If adding code to your functions.php file, use a child theme to prevent your changes from being overwritten during theme updates.
  • Plugin Conflicts: Some issues, like the entire cache purging when a new post is created, have been acknowledged by the 'WP-Optimize' team as bugs in past versions. Ensure your plugin is updated to the latest version, as some reported behaviors may have been resolved.
  • CDN and Other Caches: If you are using a Content Delivery Network (CDN) or another caching plugin in conjunction with WP-Optimize, you may need to configure cache purging there as well.

While the 'WP-Optimize' plugin provides powerful caching and optimization tools, fine-tuning its automatic purging behavior often requires these custom code solutions. The community has found these filters to be effective for managing cache based on their specific content update workflows.

Related Support Threads Support