• Hi folks,

    I’ve actually posted this question on Stack Overflow, but they didn’t have an answer for me. Here’s the question:

    I’m curious about how the WP Super Cache plugin works. It is a plugin that caches certain pages on WordPress so that the server doesn’t have build the page every time it is requested.

    I’ve read around a little about how server-side caching in WordPress works, and I found this post, which says that you can add a filter to ‘posts_request’ hijack and stop the main query (which kickstarts the whole page building in WordPress), and another filter to ‘posts_results’ to insert your own cached page. Between these two filters, you can stop WordPress from building a page from scratch.

    I’ve been pouring through the WP Super Cache scripts though, and I don’t find any filters for these two actions anywhere! Does anyone have any idea of how WP Super Cache hijacks the main post loop?

Viewing 4 replies - 1 through 4 (of 4 total)
  • It doesn’t. It starts an output buffer before anything is sent to the browser, and when the page is complete saves the content to a file and sends that content to the browser. Look for “ob_start” in the plugin, then look at the callback function that saves everything.

    The page could have a post loop, or not. The plugin doesn’t care. ??

    For invalidating cache files it does care though, mainly to find the right files to delete when a post is edited.

    Thread Starter Terence Pek

    (@terresquall)

    Hey Donncha,

    Thanks for the quick reply. How does the plugin stop the page from rendering (so that it can display data from a cached file) though? Because once you cache a file for the first time, you wouldn’t need to render the file again until it updates.

    WordPress has hooks that load a caching system if a constant “WP_CACHE” is defined. That loads the caching plugin before most of WordPress loads. All you have to do is match the current URL+browser cookies+whatever to a cached file and send it to a browser with the right headers, then simply exit before WordPress properly loads.

    WP_CACHE is set in wp-config.php, then wp-settings.php loads everything else.

    Thread Starter Terence Pek

    (@terresquall)

    Hi Donncha,

    Sorry, I’m stuck again. So I have to modify the user’s wp-config.php file to define WP_CACHE. After that is done, which actions / filters do I hook my own functions onto to display a cached HTML page?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How does WP Super Cache hijack the main query loop?’ is closed to new replies.