[wp-hackers] Feed Caching
iPhoneclub
jp.horn at gmail.com
Sat Sep 18 04:22:24 UTC 2010
This has been discussed before, but I can't seem to wrap my head
around it. Since WordPress 2.9 there is an extra context $url filter
for the filter 'wp_feed_cache_transient_lifetime'. I haven't seen any
code examples on the web how this is supposed to work :-( What I'm
trying to achieve is a per-feed cache setting, instead of the global
custom function for wp_feed_cache_transient_lifetime method (like:
http://wpengineer.com/1820/feed-cache-in-wordpress/). Dougal posted a
workaround (http://dougal.gunters.org/blog/2010/05/20/quick-tip-faster-
wordpress-news) for per-feed filtering, but I don't know if that's
still the correct way:
// Customize the Planet WordPress news feed update time:
add_filter( 'wp_feed_cache_transient_lifetime',
'dc_reschedule_rss_fetch', 10, 2 );
function dc_reschedule_rss_fetch( $lifetime, $url ) {
if ( false !== strpos( $url, 'planet.wordpress.org' ) ) {
$lifetime = 7200; // expire after 2 hours (7200 seconds)
}
return $lifetime;
}
I also found this post, with contributions by Otto and Rarst, but that
snippet doesn't seem to work for me:
http://www.wptavern.com/forum/troubleshooting/767-setting-cache-duration-simplepie-wordpress.html
The current filter is:
$feed-
>set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime',
43200, $url));
How do I pass a specific feed url and a specific (shorter than
default) cache time to this filter in my theme's functions.php? I need
one feed to refresh every 5 minutes, while caching other feeds for one
hour (I have five external feeds in total).
Any help would be greatly appreciated!
More information about the wp-hackers
mailing list