• Resolved fkoomek

    (@fkoomek)


    Hello.

    Is it possible to call preload function programatically? I would like to call preload every time the cache is purged.

    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Venkat Raj

    (@webulous)

    @fkoomek You could use Schedule preloader option and set schedule type as same as cache lifespan

    This runs preload whenever the cache is purged.

    Thread Starter fkoomek

    (@fkoomek)

    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

    Plugin Contributor Venkat Raj

    (@webulous)

    Hi @fkoomek

    You can use this hook wpo_cache_flush to do that.

    Thread Starter fkoomek

    (@fkoomek)

    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"
    Plugin Contributor Venkat Raj

    (@webulous)

    @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

    Thread Starter fkoomek

    (@fkoomek)

    @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}:

    Plugin Contributor Venkat Raj

    (@webulous)

    @fkoomek That is because upon plugin deactivation the cache are purged and started to preload again. We’ll look into this.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘call Preload function’ is closed to new replies.