FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home » Optimization »  Hack WP-Cache for Maximum Speed

Hack WP-Cache for Maximum Speed

by Charles Torvalds 2 comments

[hide]

If you desire SPEED from your WordPress blog, the #1 speed improvement comes from using the WP-Cache Plugin. However, if you still desire even more speed after installing the Plugin, you can modify the WP-Cache Plugin code run even faster!

WP-Cache Speed Hack Results

WP-Cache Off
WP-Cache Off

WP-Cache Default Settings
WP-Cache On Defaults

WP-Cache With wp-cache-phase1.php Hack
WP-Cache With wp-cache-phase1.php Hack

WP-Cache With Full Hack
WP-Cache with Full AskApache Hack

These results came from the Cacheability Checker. Yslow for firefox is what you need today.

Manual Instructions for hacking wp-cache

First you should download and activate the WP-Cache Plugin, then enable it in your Options Configuration Panel for WP-Cache.

Open wp-cache-phase1.php

Find

      /* No used to avoid problems with some PHP installations
      $content_size += strlen($log);
      header("Content-Length: $content_size");
      */

Replace with

      // BEGIN AskApache WP-Cache hack
      $content_size += strlen($log);
      header("Content-Length: $content_size");
      // END AskApache WP-Cache hack

Open wp-cache-phase2.php

Find

  /* Not used because it gives problems with some
   * PHP installations
  if (!$response{'Content-Length'}) {
  // WP does not set content size
    $content_size = ob_get_length();
    @header("Content-Length: $content_size");
    array_push($wp_cache_meta_object->headers, "Content-Length: $content_size");
  }
  */

Replace with

  // BEGIN AskApache WP-Cache Hack
  if (!$response{'Content-Length'}) {
    $content_size = ob_get_length();
    @header("Content-Length: $content_size");
    array_push($wp_cache_meta_object->headers, "Content-Length: $content_size");
  }
  // END AskApache WP-Cache Hack

Find

  if (!$response{'Content-Type'}) {
    $value =  "text/html; charset=\"" . get_settings('blog_charset')  . "\"";
    @header("Content-Type: $value");
    array_push($wp_cache_meta_object->headers, "Content-Type: $value");
  }

After Add

  // BEGIN AskApache WP-Cache Hack
  if (!$response{'Cache-Control'}) {
      $value = "max-age=$cache_max_time, public";
      @header("Cache-Control: $value");
      array_push($wp_cache_meta_object->headers, "Cache-Control: $value");
  }
  // END AskApache WP-Cache Hack

Download the Modified WP-Cache Plugin

Just download and install as if it were the actual WP-Cache Plugin.wp-cache.zip | wp-cache.rar

Want More Speed?

Then check out the other speed articles on AskApache.

Or just add this to your blogs .htaccess file.

#           HEADERS and CACHING
# 1 YEAR
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Pragma
Header unset Last-Modified
Header unset ETag
FileETag None
</FilesMatch>
 
# 2 DAYS
<filesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
Header unset Pragma
Header unset Last-Modified
Header unset ETag
FileETag None
</FilesMatch>
 
# 2 HOURS
<filesMatch ".(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
Header unset Pragma
Header unset ETag
FileETag None
</FilesMatch>
 
# COMPRESSION
<filesMatch ".(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>

March 11th, 2008

Comments Welcome

  • http://3oneseven.com/ milo

    How does this work with the speedy cache plugin url=aciddrop.com ?

  • http://www.cekay.de cekay

    Seems the Heade modifications doesnt work on my hosts apache server. too bad.
    If I modify the code as describet manual, the pages are shown as source html.
    and if i download your version i get this error:

    Fatal error: Class 'CacheMeta' not found in /www/public_html/w0098a5f/wp-content/plugins/wp-cache/wp-cache-phase2.php on line 39

    I use Wordpress 2.6 and PHP 5. Any time for suggestions how i can check if i can enable header stuff at my provider ?

    thank you

My Online Tools

Related Articles
Twitter

  • askapache: Today in 1965 DEC announces PDP-8
  • hubail: RT @askapache: Make sure you unplug your Ethernet when leaving the room, or disable wifi
  • askapache: Make sure you unplug your Ethernet when leaving the room, or disable wifi
  • askapache: My servers, and me, are getting annoyed. Fail2ban works fairly well against all the Chinese brute forcing going on
  • askapache: Can't the Chinese stop ordering their hackers to hack us? Ugh
  • askapache: All I want for my bday is a bottle of American whiskey :)
  • askapache: The first Dino fossil wasn't found until 1822, we sure are young
  • askapache: Htaccess - Ultimate HowTo:  t.co/XMmRKFIWuG 
  • askapache: Show Events that Occurred on this day in the Past:  t.co/5u33s4OolA 
  • askapache: Linux / UNIX: Create Large 1GB Binary Image File With dd Command  t.co/2xs3pvudOz  via @nixcraft

My Picks
Newest Posts

WordPress Development
Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman






It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain