Updating WordPress RSS feed cache time

Photo on Visual Hunt

I found out recently – via client complaint, of course – that the default cache time for RSS feeds read by WordPress is 12 hours. Can you believe that?! WordPress may wait 12 whole hours before revisiting a feed it has already read before. Now this might have been quite adequate and considered “timely” a decade ago, but now it feels like molasses. I discovered this while using the excellent and very flexible RSSImport plugin. We were showing my client’s blog posts from another site she is published on using the this plugin, but it wasn’t reflecting a recent post from 4 hours prior. Now some delay seems natural, but after clearing the caching provided by the web host and still seeing nothing, I decided to dig in.

The way I am using the plugin has it calling the SimplePie library built into WordPress. It does this through the fetch_feed function. It includes a nice filter hook we can use to update the WordPress RSS feed cache time.

We can use this wp_feed_cache_transient_lifetime hook to alter the cache time to be shorter. We can either do this for all feeds processed through this function or we can do it selectively for our feed. In this case I’ve decided to alter the behavior just for my client’s blog feed. I can do this by creating  my own function in my theme’s functions.php and attaching it to this filter hook like this:

Obviously you’ll need to update the URL string to match the RSS feed you are targeting. Or you could just do a blanket update to the and have this change apply to the caching of all feeds.

No matter how you decide to tackle this, I hope you’ll find this helpful when needing to update the WordPress RSS feed cache time.

What do you think?