WordPress.org

Ready to get started?Download WordPress

Plugin Directory

!This plugin hasn't been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

WP Cache Block

Adds ability to globally cache certain segments of code.

  1. Upload wp-cache-block folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Add cache block areas to the slower parts of your theme. See below.

Adding a cache block only requires wrapping the section of content you want to cache in a couple of lines of code. The key is make sure that the cache block is uniquely idtentified based on the content it will render.

For simple content that is the same on every page:

<?php if(wp_cacheblock_start('my-content')) : ?>
//the content you want to cache
<?php endif; wp_cacheblock_end(); ?>

Content that varies based on page, user, etc, will need to use key builders. Key builders are simple classes that help make a unique key for the block of content based on different parameters.

For caching the_loop in index.php you'll need to add a Query_Unique_Key_Builder which creates a key based on passed in query_var keys:

<?php $key_builders = array(new Query_Unique_Key_Builder( array ('paged') ) );
<?php if(wp_cacheblock_start( 'index-loop', array('key_builders'=> $key_builders) ) ) : ?>
  //the post loop
<?php endif; wp_cacheblock_end(); ?>

To cache the comment output, you can use the Pending_Comment_Unique_Key_Builder so users with pending comments will get their own cached page.

<?php $key_builders = array( new Pending_Comment_Unique_Key_Builder() );
<?php if(wp_cacheblock_start('index-loop', array('key_builders'=> $key_builders) ) ) : ?>
  //the comment loop
<?php endif; wp_cacheblock_end(); ?>

If you're having to render complex data per user, the Per_User_Unique_Key_Builder will help create a unique key per user for the content:

<?php $key_builders = array( new Per_User_Unique_Key_Builder() );
<?php if(wp_cacheblock_start('index-loop', array('key_builders'=> $key_builders) ) ) : ?>
  //the user specific content
<?php endif; wp_cacheblock_end(); ?>

Requires: 2.8 or higher
Compatible up to: 3.0.5
Last Updated: 2011-2-14
Downloads: 2,680

Ratings

4 stars
4.8 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,2,2
100,1,1
100,1,1