• Resolved fkoomek

    (@fkoomek)


    Hello.
    Is it possible to run the preload function from start to beginning according to the sitemap and then stop?
    I got a complaint from my host provider that the preload is too aggressive and that it runs continuously. Is there a function that I could use?
    Thanks,

    Radan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @fkoomek

    Thank you for reaching out and I am happy to help!

    Yes, the cache preload runs until the website is preloaded and then starts from the beginning. You can try adding a smaller amount of pages and increasing the interval.
    This will ensure less server consumption. Alternatively, you can disable wp_cron and use wp-cli:
    wp w3-total-cache pgcache_prime [–start=<start>] [–limit=<limit>]

    The idea of the cache priming is that you always have fresh cache served for the visitors. There is a chance that the cache is purged if triggered by altering the pages adding or changing some plugin settings, adding a new post, etc. and you want the cache preload to kick in in this case.

    I am not sure which settings are used for cache priming in yoru case, however, the default 10 pages per 900s should not cause a lot of server resource consumption.

    I hope this helps!

    Thanks!

    Thread Starter fkoomek

    (@fkoomek)

    Thank you for your help.
    I understand but I would rather clear and preload the cache all at once in some given interval. So what I did now is that I disabled the priming of the cache automatically ind your plugin and instead I use this code:

    /*w3tc preload manually*/
    // Schedule the event
    add_action('init', 'schedule_pgcache_prime');
    function schedule_pgcache_prime() {
        // Get the current time in the Prague time zone
    date_default_timezone_set('Europe/Prague');
    $current_time = current_time('timestamp', true);
    // Get the current hour and minute separately
    $current_hour = date('G', $current_time);
    $current_minute = date('i', $current_time);
    		
    if (($current_hour == 0 && $current_minute >= 10) || ($current_hour == 1) || ($current_hour == 2 && $current_minute < 10)) {
            // Schedule the event to run every minute
            if (!wp_next_scheduled('w3_pgcache_prime')) {
            wp_schedule_event(time(), 'every_minute', 'w3_pgcache_prime');
    		}
    	   }
    		else{
    	// Unschedule the 'w3_pgcache_prime' event
    wp_clear_scheduled_hook('w3_pgcache_prime');
    	}
    }

    I am also calling w3tc_flush_all(); before the preload begins.
    So, now the cache is cleared at 0:10, and then preload starts from 0:10-2:10 which is enough to finish it and then it stops. It’s true that I am using pretty aggressive preload 30pages/minute.

    Radan

    • This reply was modified 1 year, 1 month ago by fkoomek.
    • This reply was modified 1 year, 1 month ago by fkoomek.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Preload cache and stop’ is closed to new replies.