WordPress.org

Ready to get started?Download WordPress

Forums

Quick Cache (Speed Without Compromise)
[resolved] How to call clear cache from function.php (7 posts)

  1. marena
    Member
    Posted 4 months ago #

    Hi, can someone tell me how to call clear cache from function.php.

    Now I need to clear cache after editor change something in advanced custom filed option page.

    Here is my code to catche update action:

    function acf_clear_cache($post_id) {
    if ( $post_id == 0 || $post_id == 'options' ) {
    // call clear cache
    }
    return $post_id;
    }

    add_action('acf/save_post', 'acf_clear_cache', 1);

    Thanks for help.

    https://wordpress.org/plugins/quick-cache/

  2. Raam Dev
    Member
    Plugin Author

    Posted 3 months ago #

    Hello,

    You can do it like this:

    add_action( 'save_post', 'my_custom_clear_cache', 10, 1 );
    
    function my_custom_clear_cache( ) {
        $GLOBALS['quick_cache']->clear_cache();
    }
  3. marena
    Member
    Posted 3 months ago #

    Thank you very much!

  4. telepisodesch
    Member
    Posted 3 months ago #

    Hi the following code clears all the cache right? how about if I just want to clear a cache of a specific page or URL, how will I do that in function.php ?

    add_action( 'save_post', 'my_custom_clear_cache', 10, 1 );
    
    function my_custom_clear_cache( ) {
        $GLOBALS['quick_cache']->clear_cache();
    }
  5. Raam Dev
    Member
    Plugin Author

    Posted 3 months ago #

    You should be able to accomplish that by passing the page or post ID to the auto_purge_post_cache() function like this:

    add_action( 'save_post', 'my_custom_clear_cache', 10, 1 );
    
    function my_custom_clear_cache( ) {
        $post_id = 123;
        $GLOBALS['quick_cache']->auto_purge_post_cache($post_id);
    }
  6. telepisodesch
    Member
    Posted 3 months ago #

    wow thank you for the reply!

    another question :)

    how about clearing the cache of the category / archive page and a custom page. For example in my site, I created a custom page that lists all posts with recent updates on custom fields and content (e.g. mydomain[.]tld/mycustom.php ---> which I 301 to --> /updates/ (cached via the ?qcAC=1 parameter).

    Those commands above are clearing the cache immediately?

  7. Raam Dev
    Member
    Plugin Author

    Posted 3 months ago #

    how about clearing the cache of the category / archive page and a custom page.

    The custom page would be cleared the same way, by passing the ID of the custom page to auto_purge_post_cache(). There is no function currently to clear a specific category cache.

    There is a feature request open for specifying a list of specific URIs that should be purged when a post is published, so after that feature gets implemented there will likely be a function you can call to purge a specific URI. You may want to follow that GitHub issue for updates.

    If you have any further questions, please open a new support thread, as this one is already marked as resolved.

Reply

You must log in to post.

About this Plugin

About this Topic