This documentation is only valid for older versions of Wordfence. If you are using Wordfence 7 or later, please visit our new documentation.


From Wordfence Documentation
Jump to: navigation, search

Wordfence has a function that we make available to other PHP developers called wordfence::doNotCache()

As a PHP developer you'll recognize that this function lives in the Wordfence class as a static public function. That means that anyone can call doNotCache() and they need to prefix it with the class name wordfence::doNotCache()

This function tells Wordfence to disable caching for the current request. If you call this from anywhere in WordPress or a theme or plugin, the current page that is busy being generated will not be cached. Note that if the page has already been cached, then this does not clear the cache. So if you make a code change that incorporates wordfence::doNotCache() into your code, make sure you then sign-into your website, go to the Wordfence > Performance Setup menu and clear the cache. 

The rest of this document is a technical description of how we implement wordfence::doNotCache() and it's not required reading if you simply want to use the function. 

The way Wordfence caching works is as follows:

  1. Request arrives at the web server level. 
  2. Web server passes that request to PHP which starts executing WordPress and all its plugins.
  3. Wordfence tells PHP that it wants to see whatever WordPress and its themes and plugins have generated before that output is sent to the client. Wordfence does this by calling the PHP ob_start() function and telling PHP to send the output to wfCache::obComplete() function when it has finished processing and is going to send output to the browser. When doing this Wordfence checks if you've called the wordfence::doNotCache() function and if you have then it doesn't tell PHP to capture the output. 
  4. Then once PHP sends output to the browser, it first sends it to Wordfence by calling the wfCache::obComplete() function. Once again Wordfence checks if you've called wordfence::doNotCache() and if you have then it doesn't cache the output. The reason we do a second check is because you may have called doNotCache later in the execution cycle after we set up caching initially. So we do a second check and if you called it then we don't cache the page. 
  5. If you didn't call wordfence::doNotCache() then Wordfence stores two versions of the page on disk: The first version is uncompressed and the second is compressed which makes Falcon cache even faster because it saves your web server from recompressing pages when sending responses to browsers that support compression.