Title: Disable/enable cache programmatically
Last modified: January 13, 2026

---

# Disable/enable cache programmatically

 *  Resolved [mistercode](https://wordpress.org/support/users/mistercode/)
 * (@mistercode)
 * [3 months ago](https://wordpress.org/support/topic/disable-enable-cache-programmatically/)
 * I write a custom plugin to import WooCommerce from a custom CRM. I need to purge
   and disable the cache before importing and enable the cache afterwards programmatically.
 * Unfortunately, I can’t find any action or filter that I could use for this. Could
   you please give me a solution that will allow me to achieve this goal?
 * Thank you in advance!

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

 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 months, 4 weeks ago](https://wordpress.org/support/topic/disable-enable-cache-programmatically/#post-18784518)
 * you probably don’t need to disable/enable it , but just purge it afterwards
 * for that you can use `do_action( 'litespeed_purge_all' );` or `do_action( 'litespeed_purge_post',
   123 );` to purge by post ID where 123 is the post ID
 *  Thread Starter [mistercode](https://wordpress.org/support/users/mistercode/)
 * (@mistercode)
 * [2 months, 4 weeks ago](https://wordpress.org/support/topic/disable-enable-cache-programmatically/#post-18784599)
 * Thank you [@qtwrk](https://wordpress.org/support/users/qtwrk/) for your time 
   and answer.
 * I definitely need to disable LSC as it clears the cache in between writing the
   products and this sometimes causes problems.
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 months, 4 weeks ago](https://wordpress.org/support/topic/disable-enable-cache-programmatically/#post-18784669)
 *     ```wp-block-code
       do_action( 'litespeed_disable_all', 'Reason to stop debugging' );
       ```
   
 * then you can try this
 *  Thread Starter [mistercode](https://wordpress.org/support/users/mistercode/)
 * (@mistercode)
 * [2 months, 4 weeks ago](https://wordpress.org/support/topic/disable-enable-cache-programmatically/#post-18784677)
 * And how to re-enable it?
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 months, 4 weeks ago](https://wordpress.org/support/topic/disable-enable-cache-programmatically/#post-18784680)
 * it will be autoamtically turn it on on next request
 * pseudo code during your import process:
 *     ```wp-block-code
       // other ocde do_action( 'litespeed_purge_all' ); // purge all before turning offdo_action( 'litespeed_disable_all', 'Reason to stop debugging' );  // turning off on the fly// your importing process....
       ```
   
 * then on next request , as long as it doesn’t go into your import code , it will
   have LSCWP on as it was

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

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdisable-enable-cache-programmatically%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * Last activity: [2 months, 4 weeks ago](https://wordpress.org/support/topic/disable-enable-cache-programmatically/#post-18784680)
 * Status: resolved