Title: Flush cache automatically
Last modified: March 4, 2021

---

# Flush cache automatically

 *  Resolved [Beats247](https://wordpress.org/support/users/beats247/)
 * (@beats247)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/)
 * Hi [@vmarko](https://wordpress.org/support/users/vmarko/),
    after further testing
   I recognized that my ajax search function and modal view popup stopped loading
   with caching. I needed to flush the cache manually so it was working again. I
   didn’t find any option to set an automatic cache purge option in your plugin 
   though. I’m not sure what cache is causing the issue though but I found this 
   code to flush the entire cache. Is this still working? My cron jobs are set to
   manual and execute every 30 minutes but it should still be running. It looks 
   like the issue appears every 3-4 hours so I would test it with 4 hours now. That
   would mean I’d need to replace ‘daily’ with ‘14400’, correct?
 *     ```
       // Scheduled Action Hook 
               function w3_flush_cache( ) { 
           	$w3_plugin_totalcache->flush_all(); 
           }     
       // Schedule Cron Job Event 
               function w3tc_cache_flush() { 
           	if ( ! wp_next_scheduled( 'w3_flush_cache' ) ) { 
           	       wp_schedule_event( current_time( 'timestamp' ), 'daily', 'w3_flush_cache' ); 
           	} 
           }      
           add_action( 'wp', 'w3tc_cache_flush' ); 
       ```
   
 * Any thoughts on that and do you know what could cause the issue?
    See: [https://prnt.sc/10d3qrn](https://prnt.sc/10d3qrn)
   and [https://prnt.sc/10d3rg9](https://prnt.sc/10d3rg9)
 * Thank you!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fflush-cache-automatically%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Thread Starter [Beats247](https://wordpress.org/support/users/beats247/)
 * (@beats247)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14136159)
 * Edit: Ok, I have checked the issue further. It happens even quicker. You just
   need to visit the home page (search is working), go to a product page (search
   is working), go back to the home page and the search is not working anymore. 
   I had to disable page caching for now as it seems to block ajax requests somehow
   or is caching them and then they don’t work anymore.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14138129)
 * Hello [@beats247](https://wordpress.org/support/users/beats247/)
 * I am sorry about the issue you are experiencing and I am happy to assist you 
   with this.
    Can you please share which Page Cache method you are using? Also,
   Is the option Cache URIs with query string variables enabled in Performance>Page
   Cache? Can you please re-enable Page Cache and try disabling Browser Cache, save
   all settings and purge the cache and see if the issue persists? If the issue 
   is still there, possibly the expires header for js files may be causing this.
   Thanks!
 *  Thread Starter [Beats247](https://wordpress.org/support/users/beats247/)
 * (@beats247)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14139637)
 * Hey [@vmarko](https://wordpress.org/support/users/vmarko/),
    thanks for your 
   reply. I am using “Disk:enhanced” for Page caching. The caching option for query
   strings variables is not enabled, it is even greyed out. When enabling Page cache
   again and disabling Browser Cache, the issue still persists. If the expires header
   for js files is causing this, what do I need to change then? Thanks again!
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14140583)
 * Hello [@beats247](https://wordpress.org/support/users/beats247/)
 * If the issue was still there once BC was disabled then the issue is not related
   to expires header set.
    have you tried adding the `/?wc-ajax=martfury_search_products`
   to page exclusion in Performance>Page Cache>Advanced> Never cache the following
   pages: Thanks!
 *  Thread Starter [Beats247](https://wordpress.org/support/users/beats247/)
 * (@beats247)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14141000)
 * Hello [@vmarko](https://wordpress.org/support/users/vmarko/),
    I have tested 
   it and added it to excluded but when I open the site in inkognito browser mode
   the search function isn’t working anymore (error 403). It not only blocks the
   ajax search function, also the modal product popups loaded with ajax (product
   reviews) and also the ajax sales notification popups (at least on first load).
   I added these ajax requests to the excluded list from page caching
 * /?wc-ajax=martfury_search_products
    /?wc-ajax=martfury_product_quick_view
 * However, it seems like it doesn’t have any influence although everything is working
   fine when I disable page caching entirely.
    Thanks again!
 * Edit: What’s really odd is that the trigger is always going back to the home 
   page again. You can visit every other page twice without breaking it, only going
   back to the home page causes this issue. That’s why I excluded the front page
   from page caching now which seems to work? It’s not an ideal solution though.
   The issue with the non-working popup remains on first load on all other cached
   pages.
 *  Thread Starter [Beats247](https://wordpress.org/support/users/beats247/)
 * (@beats247)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14146203)
 * Never mind, even disabling page caching for the front/home page doesn’t help.
   On the long run there are 403 errors for ajax actions on product pages as well.
   I have to deactivate it completely, unfortunately 🙁
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14150965)
 * Hello [@beats247](https://wordpress.org/support/users/beats247/)
 * Thank you for the info. Can you please share what you’ve had to deactivate completely?
   
   Thanks!
 *  Thread Starter [Beats247](https://wordpress.org/support/users/beats247/)
 * (@beats247)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14151120)
 * Hi [@vmarko](https://wordpress.org/support/users/vmarko/),
    I had to deactivate
   page caching from your plugin completely as excluding the front page in your 
   page cache settings (“Don’t cache the front page”) didn’t entirely solve the 
   problem. It seems like this isn’t working together with the ajax features of 
   the site somehow.
 *  Thread Starter [Beats247](https://wordpress.org/support/users/beats247/)
 * (@beats247)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14167203)
 * The issue is not “resolved”, but thanks anyway.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14167561)
 * Hello [@beats247](https://wordpress.org/support/users/beats247/)
 * Sorry about this. I was taking care of multiple topics.
    Anyway, let’s re-cap.
   Calling ajax requests is used to bypass the cache. – You stated that the issue
   happens when Page Cache is enabled. – You also started that you are using the
   Disk: Enhanced caching method. – When Page Cache is disabled the issue is gone.
   Now please understand that we cannot test the plugin with all the themes out 
   there and their functions. This is also the first time I am seeing this kind 
   of issue and I cannot think of the reason why would page cache disable search
   on any page and especially the front page. By simple logic, it may be a minify
   issue. Be that as it may, you may want to try switching the caching method to
   Disk: Basic and see if the issue persists. Have you tried reaching out to the
   support of the theme you are using and as about the compatibility issues with
   any caching plugins? Thanks!

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

The topic ‘Flush cache automatically’ is closed to new replies.

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

 * 10 replies
 * 2 participants
 * Last reply from: [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/flush-cache-automatically/#post-14167561)
 * Status: resolved