Title: Purge cache programmatically
Last modified: April 8, 2020

---

# Purge cache programmatically

 *  Resolved [argdev](https://wordpress.org/support/users/argdev/)
 * (@argdev)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/purge-cache-programmatically/)
 * Hello,
 * I am creating a webhook function and I need a way to clear all the cached assets
   programmatically, the plugins uses the clearAllCache function in WpAssetCleanUp\
   OptimiseAssets\OptimizeCommon but I can’t make it work inside my function.
    Note
   that I need to purge everything because the webhook is run once I update code
   like .js or .css, thanks.
 * What I have so far is:
 *     ```
       function clear_cache_all( $return_args, $identifier, $response_body ){
   
           $custom_action = new WpAssetCleanUp\OptimiseAssets\OptimizeCommon;
   
           $foo = $custom_action->clearAllCache(false); // the assets are never purged
   
           return $return_args;
   
       }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Gabe Livan](https://wordpress.org/support/users/gabelivan/)
 * (@gabelivan)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/purge-cache-programmatically/#post-12646777)
 * [@argdev](https://wordpress.org/support/users/argdev/) although the method’s 
   name is _clearAllCache_ (perhaps it would be renamed at some point), it doesn’t
   go through literally all .css and .js files and deletes them. Whenever the “Settings”
   page is updated as well the CSS/JS manager (e.g. you unload a CSS file, the cache
   should be re-built as you might have that file inside a combine CSS file), the
   function clears outdated CSS/JS based on the “Clear previously cached CSS/JS 
   files older than (x) days” option from “Settings” -> “Plugin usage preferences”.
 * Active CSS/JS are never deleted, otherwise, it will break the website’s layout.
   Also, you might have older CSS/JS referenced by Google Cache or old cached HTML
   pages. That’s why some of the files are kept. As you likely know caching can 
   be a tricky thing and the last thing a customer expects is a broken website. 
   I’ve seen caching mechanisms that were clearing everything and when you previewed
   the website via Google Cache or accessed certain cached HTML pages (e.g. by the
   hosts caching engine that wasn’t cleared yet), then the entire layout was broken,
   not desirable, even for the small percentage of visitors accessing it.
 * > the plugins uses the clearAllCache function in WpAssetCleanUp\OptimiseAssets\
   > OptimizeCommon but I can’t make it work inside my function.
 * What exactly is not purged? Can you be more specific?
 *  Plugin Author [Gabe Livan](https://wordpress.org/support/users/gabelivan/)
 * (@gabelivan)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/purge-cache-programmatically/#post-12714718)
 * [@argdev](https://wordpress.org/support/users/argdev/), as I didn’t hear from
   you and everything, is working fine with the clearing of the caching (no other
   reports being made by any other user), I’ll mark this topic as “resolved”. If
   you still have any issues, feel free to post them here!
 *  Thread Starter [argdev](https://wordpress.org/support/users/argdev/)
 * (@argdev)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/purge-cache-programmatically/#post-12716958)
 * Hey there,
 * Sorry that I didn’t reply. I thought I did.
 * Basically I need to emulate the to bar button Clear cached assets/js.
 * I administer some sites and whenever I update some css or js files I have to 
   flush W3TC and your plugin’s cache. For the former I can do it with a webhook
   and a function but for yours I wasn’t able yet.
 * Basically I need a guy to do what the button on the admin but inside my function.
 * Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Purge cache programmatically’ is closed to new replies.

 * ![](https://ps.w.org/wp-asset-clean-up/assets/icon-256x256.png?rev=1981952)
 * [Asset CleanUp: Page Speed Booster](https://wordpress.org/plugins/wp-asset-clean-up/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-asset-clean-up/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-asset-clean-up/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-asset-clean-up/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-asset-clean-up/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-asset-clean-up/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [argdev](https://wordpress.org/support/users/argdev/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/purge-cache-programmatically/#post-12716958)
 * Status: resolved