5

How do I turn off the WP Super Cache & W3 Total Cache functionality programmatically? For instance, I neither want to make it use the cache on some requests nor cache the output of the request, do they support that using filters? I couldn't find anything useful in their documentation.

3
  • Why would you want to disable the cache? There's no reason to ever do that.
    – Otto
    Commented Oct 4, 2012 at 14:26
  • 1
    I am working on a mobile theme plugin, so need to make sure that it gets served directly, without affecting the main site. This seems like the way out unless both plugins support caching mobile pages in someway?
    – Ashfame
    Commented Oct 4, 2012 at 14:30
  • 1
    I know this is old, but this link talks about how to programmatically flush the cache, in case it's helpful to anyone: wordpress.stackexchange.com/questions/7112/…
    – David Hobs
    Commented Mar 9, 2013 at 23:57

3 Answers 3

7

Easiest way to do this was to define a constant programmatically:

// Tell WP Super Cache & W3 Total Cache to not cache WPReadable requests
define( 'DONOTCACHEPAGE', true );
2
  • This only disables caching the page but still allows to serve already cached content. Commented Feb 26, 2018 at 8:53
  • @AlexeyKosov Don't remember that being the case but it has been years.
    – Ashfame
    Commented Feb 26, 2018 at 9:50
1

Both plugins you mention have settings pages that allow you to add directories or specific files to not cache.

These setting files are saved as text files in the relevant directory. You should be able to programatically 'append' your /mobile-theme/ directory to these settings files.

0

As per this question, you can use fragment caching to exclude specific things from being cached:

Edit your templates to with the following syntax to ensure that dynamic features remain so: Example 1:

<!-- mfunc any PHP code --><!-- /mfunc -->

Example 2:

<!-- mfunc -->any PHP code<!-- /mfunc -->

Example 3:

<!--MFUNC           -->
                                      echo rand();
<!--/mfunc -->

Example 4:

<!-- mclude path/to/file.php --><!-- /mclude -->

Example 5:

<!-- mclude -->path/to/file.php<!-- /mclude -->

Not the answer you're looking for? Browse other questions tagged or ask your own question.