Changeset 1291

Show
Ignore:
Timestamp:
05/15/08 17:38:20 (7 months ago)
Author:
donncha
Message:

Allow Magpie RSS class to use a global cache or sitemeta for caching feeds

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/rss.php

    r1218 r1291  
    673673\*=======================================================================*/ 
    674674        function set ($url, $rss) { 
    675                 global $wpdb
     675                global $wpdb, $wp_object_cache
    676676                $cache_option = 'rss_' . $this->file_name( $url ); 
    677677                $cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts'; 
    678678 
    679                 // shouldn't these be using get_option() ? 
    680                 if ( !$wpdb->get_var( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name = %s", $cache_option ) ) ) 
    681                         add_option($cache_option, '', '', 'no'); 
    682                 if ( !$wpdb->get_var( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name = %s", $cache_timestamp ) ) ) 
    683                         add_option($cache_timestamp, '', '', 'no'); 
    684  
    685                 update_option($cache_option, $rss); 
    686                 update_option($cache_timestamp, time() ); 
     679                if( $wp_object_cache->cache_enabled ) { 
     680                        wp_cache_set( $cache_option, $rss, 'site-options' ); 
     681                        wp_cache_set( $cache_timestamp, $cache_timestamp, 'site-options' ); 
     682                } else { 
     683                        if( !get_site_option( $cache_option ) ) 
     684                                add_site_option( $cache_option, $rss ); 
     685                        if( !get_site_option( $cache_timestamp ) ) 
     686                                add_site_option( $cache_timestamp, $cache_timestamp ); 
     687                } 
    687688 
    688689                return $cache_option; 
     
    696697\*=======================================================================*/ 
    697698        function get ($url) { 
     699                global $wp_object_cache; 
    698700                $this->ERROR = ""; 
    699701                $cache_option = 'rss_' . $this->file_name( $url ); 
    700702 
    701                 if ( ! get_option( $cache_option ) ) { 
    702                         $this->debug( 
    703                                 "Cache doesn't contain: $url (cache option: $cache_option)" 
    704                         ); 
    705                         return 0; 
    706                 } 
    707  
    708                 $rss = get_option( $cache_option ); 
    709  
    710                 return $rss; 
     703                if( $wp_object_cache->cache_enabled ) { 
     704                        if( ! wp_cache_get( $cache_option, 'site-options' ) ) { 
     705                                $this->debug( "Cache doesn't contain: $url (cache option: $cache_option)" ); 
     706                                return 0; 
     707                        } 
     708                        return wp_cache_get( $cache_option, 'site-options' ); 
     709                } else { 
     710                        if ( ! get_option( $cache_option ) ) { 
     711                                $this->debug( "Cache doesn't contain: $url (cache option: $cache_option)" ); 
     712                                return 0; 
     713                        } 
     714                        return get_option( $cache_option ); 
     715                } 
    711716        } 
    712717 
     
    719724\*=======================================================================*/ 
    720725        function check_cache ( $url ) { 
     726                global $wp_object_cache; 
    721727                $this->ERROR = ""; 
    722728                $cache_option = $this->file_name( $url ); 
    723729                $cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts'; 
    724730 
    725                 if ( $mtime = get_option($cache_timestamp) ) { 
     731                if( $wp_object_cache->cache_enabled ) { 
     732                        $mtime = wp_cache_get( $cache_timestamp, 'site-options' ); 
     733                } else { 
     734                        $mtime = get_option($cache_timestamp); 
     735                } 
     736 
     737                if ( $mtime ) { 
    726738                        // find how long ago the file was added to the cache 
    727739                        // and whether that is longer then MAX_AGE