How to disable page cache cleaning when editing a draft
-
Hello.
I have such a problem. The site has 500 pages. Each page is cached. A total of 1000 files. When I write an article, I save it in drafts and the plugin clears all cache pages.
How to disable cache page clearing when editing a draft? I sometimes write drafts for several weeks and the cache is constantly cleared, thereby causing the load on the hosting.
-
Hello @baf285
Thank you for reaching out and I am happy to help!
W3 Total Cache does not call the cache flush when the draft is saved. Once the content is published then the flush cache is called and only for the specific page and the all the pages that ancors that page
This being said, It seems that something else, possibly a plugin or a theme is calling for the cache flushIs there a chance you can enable the Purge log and check what called w3tc_flush_all once the draft was saved?
Thanks!How to enable this journal? Can you tell me in detail how to do it?
-
This reply was modified 1 year, 6 months ago by
baf285.
Hello @baf285
Thank you for your feedback
In Perfomrance>General settings, scroll down to the Debug section, and under Purge Logs: enable Page Cache Purge Log.
Once enabled, save all settings. And test the behavior when saving the draft and check the purge log time stamp for any purge cache callsThanks!
Unfortunately, I can’t do it. This option is paid. I can’t buy your program because of illegal sanctions against my country. I’m sorry, but in such cases I will look for another program for the cache.
Hello @baf285
Thank you for your feedback.
This was the easy way to determine what is calling the cache flush.
Can you please share how you know that the cache is flushed if you save the draft and can you please share the settings you have in Performance>Page Cache>Purge Policy?Thanks!
When a cache for pages is created, it looks like this:
- _index_slash_ssl.html
- _index_slash_ssl.html_gzip
When I click save draft, the cache looks like this:
- _index_slash_ssl.html_gzip_old
- _index_slash_ssl.html_old
Performance>Page Cache>Purge Policy – Installed by default, I didn’t change anything here. There are ticks in the following places:
- Page with records
- Entry page
- RSS feed of the blog
It is written that it is not recommended to change these settings and therefore I did not change these settings.
Date
Wed, 04 Dec 2024 14:48:02 +0000
Action
flush_all
User
xxx
Stack Trace
#0 wp-includes/class-wp-hook.php(324) W3TC\PgCache_Plugin--w3tc_flush_posts (null)
#1 wp-content/plugins/w3-total-cache/CacheFlush_Locally.php(170) do_action ("w3tc_flush_posts", null)
#2 wp-content/plugins/w3-total-cache/w3-total-cache-api.php(299) W3TC\CacheFlush--flush_posts (null)
#3 wp-content/plugins/w3-total-cache/w3-total-cache-api.php(332) w3tc_flush_posts ()
#4 wp-content/plugins/seo-by-rank-math/includes/class-helper.php(239) w3tc_pgcache_flush ()
#5 wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/class-cache.php(246) RankMath\Helper--clear_cache ("sitemap/author")
#6 wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/class-cache-watcher.php(319)
RankMath\Sitemap\Cache--invalidate_storage ("author")
#7 wp-includes/class-wp-hook.php(324) RankMath\Sitemap\Cache_Watcher--clear_queued ("")
#8 wp-includes/load.php(1279) do_action ("shutdown")
#9 () shutdown_action_hook ()I managed to get a dump. I apologize. It was only for the sake of this experiment that I did this for the first time in my life.
Hello @baf285
Thank you for your feedback
There it is:/seo-by-rank-math/includes/class-helper.php(239) w3tc_pgcache_flush ()This is a well known thing and the problem is that the other plugin is calling for a cache flush:
This being said, we have a programatical way this can be prevented
Please check the link below for more details:
https://gist.github.com/mavas84/a2d07ccf922c46af23ebfc49dc15c13e
Thanks!
Thank you.
I’ve read the link, but I’m not a programmer, I don’t understand what should I do? Please help me.
Sorry.
With the help of ChatGPT, I did this:
Creating a separate plugin
If you want the changes not to depend on the active theme (for example, if you plan to change themes), you can create your own plugin:
- Log in to your server via FTP or use the file manager in the hosting control panel.
- Go to the wp-content/plugins folder.
- Create a new folder, for example, custom-w3tc-fixes.
- Inside this folder, create a file called custom-w3tc-fixes.php.
- Open this file and add the following code:
<?php
/*
Plugin Name: Custom W3TC Fixes
Description: Prevents unnecessary cache flushing in W3 Total Cache.
Version: 1.0
Author: Name
*/
add_filter( 'w3tc_preflush_posts',
function( $do_flush, $extras ) {
if ( isset( $extras['ui_action'] ) && $extras['ui_action'] == 'flush_button' ) {
return $do_flush;
}
return false;
},
99999, 2 );
add_filter( 'w3tc_preflush_all',
function( $do_flush, $extras ) {
if ( isset( $extras['ui_action'] ) && $extras['ui_action'] == 'flush_button' ) {
return $do_flush;
}
return false;
},
99999, 2 );- Save the file and return to the WordPress control panel.
- Go to the Plugins section and activate your new plugin “Custom W3TC Fixes”.
I think it worked, but the main page is still clearing. But other pages remain in the cache when I save the draft. I think this decision is very good for me. Thank you very much.
I want to offer you to make such a plugin, I think people will find this solution very useful.
-
This reply was modified 1 year, 6 months ago by
The topic ‘How to disable page cache cleaning when editing a draft’ is closed to new replies.