If you are comfortable getting into your WP theme code, I recommend just using 
PHP's APC Cache. For instance, in your header.php file where Wordpress inserts 
your header, you could slightly modify it using an if/else statement that tests 
whether the nav menu is stored in the cache. If it is already cached, it loads 
the cached copy. If it isn't cached, it runs the typical WP function for 
fetching the nav menu, loads it, and then stores it in the cache for next time.

Something like this:

<?php 
if(!empty(apc_fetch('navmenu'))){
        echo apc_fetch('nav_menu'); //echo the cached copy
}else{
        wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 
'nav-menu' ) ); //load the menu
        apc_store('nav_menu', wp_nav_menu( array( 'theme_location' => 
'primary', 'menu_class' => 'nav-menu', 'echo'=>false ) );
}
?>

You could do the exact same thing for all the other elements you want to cache. 
This is extremely granular and works very well.

Note that you may have to enable PHP APC manually on your server for this to 
work. 

Josh Welker


-----Original Message-----
From: Code for Libraries [mailto:[email protected]] On Behalf Of 
Wilhelmina Randtke
Sent: Tuesday, May 28, 2013 4:30 PM
To: [email protected]
Subject: [CODE4LIB] Wordpress: Any way to selectively control caching for 
content areas on a page?

In a Wordpress site, is there a way to allow site-wide caching, but force 
certain areas of a page to reload on each visit?

For example, if  on a specific page there is a huge navigational menu that 
never changes, a map that rarely changes, and hours of operation which change 
frequently (as often as holidays), is there a way to force only the hours of 
operation to reload when a person revisits the page?

-Wilhelmina Randtke

Reply via email to