[wp-hackers] Feed Caching

iPhoneclub jp.horn at gmail.com
Sat Sep 18 13:42:16 UTC 2010


Thanks Andrew. So something like this in functions.php should work for
overriding the standard value of 12 hours and providing an even more
aggressive cache lifetime for a specific feed?

/*
Feed Cache - Let's lower the default value to 30 minutes
*/
add_filter( 'wp_feed_cache_transient_lifetime', create_function('$a',
'return 1800;') );

/*
Even more aggressive caching for specific feeds
Hat tip Dougal (http://dougal.gunters.org/blog/2010/05/20/quick-tip-
faster-wordpress-news)
*/
add_filter( 'wp_feed_cache_transient_lifetime',
'dc_reschedule_rss_fetch', 10, 2 );

function dc_reschedule_rss_fetch( $lifetime, $url ) {
  if ( false !== strpos( $url, 'example.com/feed' ) ) {
    $lifetime = 600; // expire after 10 minutes (600 seconds)
  }
  return $lifetime;
}


More information about the wp-hackers mailing list