WordPress.org

Ready to get started?Download WordPress

Forums

How best to use cache with simplepie (1 post)

  1. Allen
    Member
    Posted 1 year ago #

    First, sorry but I also posted this in the wrong forum, but its more appropriate here.

    According to the docs, if you want to cache results for a fetch of RSS feeds with simplepie, you do this:

    add_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );
    $feed = fetch_feed( $feed_url );
    remove_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );

    My question is if I want to cache the results for several feed urls (by looping through an array), would I really want to add and remove the filter for each pass of the loop (wouldn't that cause separate entries in the cache for each feed) or should I do this:

    add_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );

    for ($i=.......){
    $feed = fetch_feed( $feed_url );
    }

    remove_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );

    Frankly (and this might be obvious), I'm confused as to how this caching works since all I've seen are examples for a single feed, rather than multiple feeds.
    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic