==== Patch <crude_rss_cache_fix> level 1
Source: 81e510b7-0ff2-0310-ae0c-f70243c84fd4:/wordpress-branches/rss_cache:2470 [local]
Target: 1a063a9b-81f0-0310-95a4-ce76da25c4cd:/trunk:2444 [mirrored]
        (http://svn.automattic.com/wordpress/trunk)
Log:
Merge rss_fix
=== wp-includes/rss-functions.php
==================================================================
--- wp-includes/rss-functions.php  (revision 2444)
+++ wp-includes/rss-functions.php  (patch crude_rss_cache_fix level 1)
@@ -10,6 +10,9 @@
 define('RSS', 'RSS');
 define('ATOM', 'Atom');
 define('MAGPIE_USER_AGENT', 'WordPress/' . $wp_version);
+define('MAGPIE_CACHE_ON',true);
+define('MAGPIE_CACHE_DIR',ABSPATH . "wp-content/cache");
+define('MAGPIE_CACHE_AGE',86400);
 
 class MagpieRSS { 
 	var $parser;
@@ -664,8 +667,16 @@
 		
 		update_option($cache_option, $rss);
 		update_option($cache_timestamp, time() );
-		
-		return $cache_option;
+		$cache_file = $this->file_name( $url );
+		$fp = @fopen( $cache_file, 'w' );
+		if ( ! $fp ) {
+			$this->error("Cache unable to open file for writing: $cache_file");
+			return 0;
+		}
+		$data = $this->serialize( $rss );                                                                      
+		fwrite( $fp, $data );                                                                                  
+		fclose( $fp );                                                                                         	    
+		return $cache_file;
 	}
 	
 /*=======================================================================*\
@@ -676,17 +687,22 @@
 \*=======================================================================*/	
 	function get ($url) {
 		$this->ERROR = "";
-		$cache_option = 'rss_' . $this->file_name( $url );
-		
-		if ( ! get_option( $cache_option ) ) {
-			$this->debug( 
-				"Cache doesn't contain: $url (cache option: $cache_option)"
-			);
-			return 0;
+		$cache_file = $this->file_name( $url );
+	    
+		if ( ! file_exists( $cache_file ) ) {
+		    $this->debug("Cache doesn't contain: $url (cache file: $cache_file)");
+		    return 0;
 		}
-		
-		$rss = get_option( $cache_option );
-		
+	    
+		$fp = @fopen($cache_file, 'r');
+		if ( ! $fp ) {
+		    $this->error("Failed to open cache file for reading: $cache_file");
+		    return 0;
+		}
+
+		$data = fread( $fp, filesize($cache_file) );
+		$rss = $this->unserialize( $data );
+        
 		return $rss;
 	}
 
@@ -701,23 +717,25 @@
 		$this->ERROR = "";
 		$cache_option = $this->file_name( $url );
 		$cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts';
+		$filename = $this->file_name( $url );
 
-		if ( $mtime = get_option($cache_timestamp) ) {
-			// find how long ago the file was added to the cache
-			// and whether that is longer then MAX_AGE
-			$age = time() - $mtime;
-			if ( $this->MAX_AGE > $age ) {
-				// object exists and is current
-				return 'HIT';
-			}
-			else {
-				// object exists but is old
-				return 'STALE';
-			}
+		if ( file_exists( $filename ) ) {
+		    // find how long ago the file was added to the cache
+		    // and whether that is longer then MAX_AGE
+		    $mtime = filemtime( $filename );
+		    $age = time() - $mtime;
+		    if ( $this->MAX_AGE > $age ) {
+			// object exists and is current
+			return 'HIT';
+		    }
+		    else {
+			// object exists but is old
+			return 'STALE';
+		    }
 		}
 		else {
-			// object does not exist
-			return 'MISS';
+		    // object does not exist
+		    return 'MISS';
 		}
 	}
 
@@ -742,7 +760,8 @@
 	Output:		a file name
 \*=======================================================================*/		
 	function file_name ($url) {
-		return md5( $url );
+		$filename = md5( $url );
+		return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) );
 	}
 	
 /*=======================================================================*\
@@ -847,4 +866,4 @@
 		return false;
 	}
 }
-?>
\ No newline at end of file
+?>
