@fkoomek You could use Schedule preloader option and set schedule type as same as cache lifespan
This runs preload whenever the cache is purged.
Hi.
I don’t think that when I clear the cache manually, preloading starts. However, I found in the code function for this:
WP_Optimize_Page_Cache_Preloader::instance()->run('manual');
How would I hook this function to the moment when I manually clear cache?
Thanks.
Radan
Hi @fkoomek
You can use this hook wpo_cache_flush to do that.
Hello. I used the code like this and it works if go to the WP-Optimize menu, click Cache, and click Clear Cache. It doesn’t work for the top bar if I click clear all cache. How to hook up there?
add_action('wpo_cache_flush ', 'purge_all_caches');
function purge_all_caches()
{
WP_Optimize_Page_Cache_Preloader::instance()->run('manual');
}
Thanks.
Radan
I am also searching for same. I figured that logged in user can call: WP_Optimize_Page_Cache_Preloader::instance()->run('manual'); But from cronjob script is not executed as it need.
It also works with bash script, but it’s not good solution for me:
#!/usr/bin/env bash
site="https://www.web.com/"
login_address="$site/wp-login.php"
log="user"
pwd="pass"
cookies="/tmp/cookies.txt"
agent="Mozilla/5.0"
# authenticate and save cookies
wget \
--user-agent="$agent" \
--save-cookies $cookies \
--keep-session-cookies \
--delete-after \
--post-data="log=$log&pwd=$pwd&testcookie=1" \
"$login_address"
# access home page with authenticated cookies
wget \
--user-agent="$agent" \
--load-cookies $cookies \
"www.web.com/test.php"
@fkoomek Both menu run a purge method which contains the hook, I mentioned. Your script worked for me for both places, except that it had a white space at the end of wpo_cache_flush
@webulous Hi. You are right. I have there extra space.
After I corrected it I am actually getting some errors and notices. For example when I deactivate some plugin a get a white screen saying :{“success”:true}:
@fkoomek That is because upon plugin deactivation the cache are purged and started to preload again. We’ll look into this.