Support » Plugin: Autoptimize » clearing cache as a network admin

  • Resolved jiggaman

    (@jiggaman)


    Hey Frank, question, as a network admin in a multisite i want to clear the cache on various subblogs from a network admin screen. I’m writing a plugin, and wanting to do the following when chooseing blog 5 in this example:

    switch_to_blog(5);
    if ( is_callable( 'autoptimizeCache::clearall' ) ) {
            $print .= "we're in";
            autoptimizeCache::clearall();
    }
    restore_current_blog();

    Unfortunately “we’re in” isn’t getting touched and clear all function never goes to work.

    Can you possible suggest the proper way to trigger your clearall function? Maybe you have something simple to suggest…

    Thanks frank!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    Not sure, maybe try with method_exists instead, e.g. :

    
    if ( method_exists( 'autoptimizeCache', 'clearall' ) ) {

    frank

    Thread Starter jiggaman

    (@jiggaman)

    I will try that. Another question perhaps, what if not using autoptimize functions I wanted to destroy all the caching of all the autoptimize caches.

    Is there a more efficient way you could suggest than switching to a blog and attempting to run that function?

    Ie manually removing files in a directy with standard php files and is there a single sql query i could run to remove all the nonces? Am I thinking about this right?

    Thanks!

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    well, I guess you could remove all of wp-content/cache/autoptimize/* with in either a shell script or with some filesystem-functions in PHP?

    Thread Starter jiggaman

    (@jiggaman)

    Reading the notes: https://developer.wordpress.org/reference/functions/switch_to_blog/

    Switch to blog wont let me access plugins on a sub blog. My goal is to create a single button i can push to clear the autoptimize cache across the whole multisite because when doing up dates I am noticing the cache cache can come out of sync with my method of edge caching. So I am getting these huge autoptimize files.

    If you can suggest any more elegant solutions…I’m all ears!

    Thanks

    Thread Starter jiggaman

    (@jiggaman)

    wp-content/cache/autoptimize/*

    as I explore: public static function clearall, i am seeing some stuff that goes beyond deleting the files: autoptimize_filter_speedupper, autoptimize_cache_warmer_protector, delete_transient( ‘autoptimize_stats’ ) etc

    Do I need to worry about that stuff?

    Thread Starter jiggaman

    (@jiggaman)

    I think i found a solution:
    Manually activating and then switching to the blog id i want, defining these variables:

    define( ‘AUTOPTIMIZE_CACHEFILE_PREFIX’, ‘autoptimize_’ );
    define( ‘AUTOPTIMIZE_CACHE_CHILD_DIR’, ‘/cache/autoptimize/’ );
    define( ‘AUTOPTIMIZE_CACHE_DIR’, autoptimizeCache::get_pathname() );

    Then running: autoptimizeCache::clearall();

    Seems to get the job done in the most light weight safest way possible.

    That said would it be more efficient and just as safe to explicitly define the path without using your functions and then write the functionality of:

    is_valid_cache_file and clear_cache_classic

    Would love to know your thoughts

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    removing all of wp-content/cache/autoptimize/* with a shell script (or with shell_exec) would probably be the easiest solution 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘clearing cache as a network admin’ is closed to new replies.