Fixed: WP Super Cache not creating meta files (and not working)

I’ve been (attempting to) set up caching on WordPress for a client, and after days (literally) of poking around, trying to figure out what was going on with both WP-Cache, and then WP-Super-Cache, I finally have an answer.

The Configuration

Everything here is happening on a completely (and very) custom theme, which is hosted on a WP 2.6.1 blog. It’s powered by 2 frontend web servers, which are transparently accessed via an LVS. The database is hosted on 2 servers, which are configured in a multiple-master configuration and are also accessed via the LVS. I’ve configued WP-Cache and WP-Super-Cache before so I’m confident I haven’t messed anything “basic” up with the configuration of the plugin.

The Problem

Let’s make sure we’re solving the same problem here. I was seeing my pages load just fine, and they even included the appended comment:

<!-- Dynamic Page Served (once) in 0.928 seconds -->

I saw that files were created in wp-content/cache/*.html but there were no files created in wp-content/cache/meta/*.meta (for WP-Super-Cache). Apparently without the meta files (which contain appropriate headers etc), the caching system assumes it can’t send the cached version, so it re-processes everything and sends the dynamic version (thus the comment).

The Solution(s)

I tried all sorts of things to get this to work, including:

  • Moving the define(‘WP_CACHE’, true) to the top of wp-config.php, just in case
  • Deleting and manually re-creating the symlink for advanced-cache.php
  • Turning on $use_flock in wp-cache-config.php
  • Modifying $sem_id in wp-cache-config.php (you never know!)
  • Banging my head repeatedly on the keyboard.

Needless to say, none of these things worked. Eventually, I came across a thread where Donncha (the author of WP-Super-Cache, and really nice guy to boot) mentions that a plugin doesn’t have an ob_end_flush() where it should. That reminded me of a post about Anarchy Media Player not working with WP-Cache that I’d seen, so I tried it out by changing the end of my footer.php theme file to look like this:

</html><?php while (ob_end_flush()) {} ?>

That seems to have fixed it! I’m now getting the beloved comment that I was looking for in my source files:

<!-- Cached page served by WP-Cache -->

and performance is way up. High-fives all around. The moral of the story is make sure you close/flush buffers in your themes and plugins. This is a bit of a hack fix for when someone doesn’t do that, but it works.

  1. beaulebens said:

    Hey Alberto, that's great news! This was so frustrating (and had
    severe consequences on the server I was working on), so I'm glad I
    could help someone else out.

  2. Erik said:

    Thanks a million!
    Turning on $use_flock in wp-cache-config.php did it for me.

    Once again, thanks a lot 🙂

  3. Jarar said:

    Lebens,
    I have the same problem with you. At the end of my source pages, I only see something like:
    </body>
    </html>
    <!– Dynamic page generated in 4.939 seconds. –>
    (WITHOUT the second line "<!– Cached page served by WP-Cache –>)

    I see my WPSuperCache admin, and there is records like: WP-Cache (2.10MB)
    * 30 Cached Pages
    * 6 Expired Pages

    WP-Super-Cache (55.10MB)
    * 224 Cached Pages
    * 942 Expired Pages
    I think the plugin working, but I wonder why the loading time bocome slower than before I use this plugin (okay, about the loading time, may be my server down, and often I get 500 internal server error when opening my homepage).

    So why there was no second line "<!– Cached page served by WP-Cache –>"?

    I am trying to add "</html><?php while (ob_end_flush()) {} ?>" at the end (means "really at the end line) of footer.php, but also not working. Or maybe I have to put the code "not at the very end" line?

    Suggestion from you would be much helpful.
    Sory Lebens for my English.
    Thank you – Jarar from Indonesia.
    (I put link to my single post, if only you can not open my homepage because my server problem these days. I will appreciate if you would send me email about my plugin problem).

Comments are closed.