Live Blog of “WordPress Caching” by Brandon Savage

16 May, 2009  |  Written by eric  |  under Home

From WordCamp Mid-Atlantic 2009 #wordcampmidatl

(slides per @brandonsavage)

  • What is caching?
  • Why we need caching?
  • Improving your code’s performance
  • Improving the content’s performance
  • Building your own caching plugin

Things that you cache…

  • code (HTML, sidebar)
  • login status (sessions, username)
  • content (MySQL queries)

Things you don’t want to cache…

  • dynamic content
  • user permissions
  • passwords
  • security settings

Why is caching important?

  • Caching improves the speed of the page load.
  • Caching reduces server load.
  • 9,829 function calls to load WordPress!

WordPress by itself is extremely inefficient!

WordPress Performance Benchmarks:

  • WordPress by itself (with plugins):  almost 6 seconds
  • APC enabled (without WP-Cache):  about 2 seconds

Caching the code

  • Opcode cache
  1. PHP is not a complied language; code is compiled and executed at run time.
  2. Compiling code takes extra time, extra CPU, and extra resources.
  • Benefits of Opcode Cache
  • Drawback of Opcode Cache
  1. Still must invoke PHP (which requires resources)
  2. Executes “expensive” stat() calls.
  3. Doesn’t play nice with some WordPress caching systems (e.g. WP-Cache)

Bottom Line:  You’re crazy if you don’t have an Opcode cache!

Caching the content

Why cache content?

  • Most blogs don’t have content changes that often.
  • Cached content reduces server load and increases delivery.
  • When high traffic shows up, you’ll be ready.

Typical WordPress process

  • WordPress loads the plugins, then the theme, then the content and returns the page to the user.

With WP-Cache

  • Checks for a cached file.
  • If found, it serves the cached file and terminates WordPress.
  • If not, it continues on with typical process and caches.

WP-Cache is a file-based cache.

File based caches:

  • Write directly to the disk, and read directly from the disk.
  • This can be slow, as a disk read is required.
  • This can be more reliable, as the files persist after Apache or MySQL start.

Drawbacks of WP-Cache

  • File based cache (slower)
  • Might have thousands of files
  • WP-Cache still required the PHP parser
  • WP-Cache evaluated the file before it serves it

Preparing for the Digg Effect

  • WP-Super-Cache
  1. Uses same code as WP-Cache
  2. Replaces dynamic page hyperlinks with static HTML page hyperlinks
  3. Removes the need for PHP parser

The rule of web servers: Static always beats dynamic.

Warning! If you used WP-Cache, it created a symlink for advanced-cache.php.

Words of caution…

  • WordPress has not initialized a databse connection or the WordPress framework at the cache execution time.

No Responses so far | Have Your Say!

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>