==== 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
==================================================================
|
|
|
|
| 10 | 10 | define('RSS', 'RSS'); |
| 11 | 11 | define('ATOM', 'Atom'); |
| 12 | 12 | define('MAGPIE_USER_AGENT', 'WordPress/' . $wp_version); |
| | 13 | define('MAGPIE_CACHE_ON',true); |
| | 14 | define('MAGPIE_CACHE_DIR',ABSPATH . "wp-content/cache"); |
| | 15 | define('MAGPIE_CACHE_AGE',86400); |
| 13 | 16 | |
| 14 | 17 | class MagpieRSS { |
| 15 | 18 | var $parser; |
| … |
… |
|
| 664 | 667 | |
| 665 | 668 | update_option($cache_option, $rss); |
| 666 | 669 | update_option($cache_timestamp, time() ); |
| 667 | | |
| 668 | | return $cache_option; |
| | 670 | $cache_file = $this->file_name( $url ); |
| | 671 | $fp = @fopen( $cache_file, 'w' ); |
| | 672 | if ( ! $fp ) { |
| | 673 | $this->error("Cache unable to open file for writing: $cache_file"); |
| | 674 | return 0; |
| | 675 | } |
| | 676 | $data = $this->serialize( $rss ); |
| | 677 | fwrite( $fp, $data ); |
| | 678 | fclose( $fp ); |
| | 679 | return $cache_file; |
| 669 | 680 | } |
| 670 | 681 | |
| 671 | 682 | /*=======================================================================*\ |
| … |
… |
|
| 676 | 687 | \*=======================================================================*/ |
| 677 | 688 | function get ($url) { |
| 678 | 689 | $this->ERROR = ""; |
| 679 | | $cache_option = 'rss_' . $this->file_name( $url ); |
| 680 | | |
| 681 | | if ( ! get_option( $cache_option ) ) { |
| 682 | | $this->debug( |
| 683 | | "Cache doesn't contain: $url (cache option: $cache_option)" |
| 684 | | ); |
| 685 | | return 0; |
| | 690 | $cache_file = $this->file_name( $url ); |
| | 691 | |
| | 692 | if ( ! file_exists( $cache_file ) ) { |
| | 693 | $this->debug("Cache doesn't contain: $url (cache file: $cache_file)"); |
| | 694 | return 0; |
| 686 | 695 | } |
| 687 | | |
| 688 | | $rss = get_option( $cache_option ); |
| 689 | | |
| | 696 | |
| | 697 | $fp = @fopen($cache_file, 'r'); |
| | 698 | if ( ! $fp ) { |
| | 699 | $this->error("Failed to open cache file for reading: $cache_file"); |
| | 700 | return 0; |
| | 701 | } |
| | 702 | |
| | 703 | $data = fread( $fp, filesize($cache_file) ); |
| | 704 | $rss = $this->unserialize( $data ); |
| | 705 | |
| 690 | 706 | return $rss; |
| 691 | 707 | } |
| 692 | 708 | |
| … |
… |
|
| 701 | 717 | $this->ERROR = ""; |
| 702 | 718 | $cache_option = $this->file_name( $url ); |
| 703 | 719 | $cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts'; |
| | 720 | $filename = $this->file_name( $url ); |
| 704 | 721 | |
| 705 | | if ( $mtime = get_option($cache_timestamp) ) { |
| 706 | | // find how long ago the file was added to the cache |
| 707 | | // and whether that is longer then MAX_AGE |
| 708 | | $age = time() - $mtime; |
| 709 | | if ( $this->MAX_AGE > $age ) { |
| 710 | | // object exists and is current |
| 711 | | return 'HIT'; |
| 712 | | } |
| 713 | | else { |
| 714 | | // object exists but is old |
| 715 | | return 'STALE'; |
| 716 | | } |
| | 722 | if ( file_exists( $filename ) ) { |
| | 723 | // find how long ago the file was added to the cache |
| | 724 | // and whether that is longer then MAX_AGE |
| | 725 | $mtime = filemtime( $filename ); |
| | 726 | $age = time() - $mtime; |
| | 727 | if ( $this->MAX_AGE > $age ) { |
| | 728 | // object exists and is current |
| | 729 | return 'HIT'; |
| | 730 | } |
| | 731 | else { |
| | 732 | // object exists but is old |
| | 733 | return 'STALE'; |
| | 734 | } |
| 717 | 735 | } |
| 718 | 736 | else { |
| 719 | | // object does not exist |
| 720 | | return 'MISS'; |
| | 737 | // object does not exist |
| | 738 | return 'MISS'; |
| 721 | 739 | } |
| 722 | 740 | } |
| 723 | 741 | |
| … |
… |
|
| 742 | 760 | Output: a file name |
| 743 | 761 | \*=======================================================================*/ |
| 744 | 762 | function file_name ($url) { |
| 745 | | return md5( $url ); |
| | 763 | $filename = md5( $url ); |
| | 764 | return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) ); |
| 746 | 765 | } |
| 747 | 766 | |
| 748 | 767 | /*=======================================================================*\ |
| … |
… |
|
| 847 | 866 | return false; |
| 848 | 867 | } |
| 849 | 868 | } |
| 850 | | ?> |
| 851 | | No newline at end of file |
| | 869 | ?> |