Changeset 10603
- Timestamp:
- 02/20/2009 02:23:11 AM (12 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r10593 r10603 666 666 } else { 667 667 $transient_option = '_transient_' . $wpdb->escape($transient); 668 // If option is not in alloptions, it is not autoloaded and thus has a timeout 669 $alloptions = wp_load_alloptions(); 670 if ( !isset( $alloptions[$transient_option] ) ) { 671 $transient_timeout = '_transient_timeout_' . $wpdb->escape($transient); 672 if ( get_option($transient_timeout) > time() ) { 673 delete_option($transient_option); 674 delete_option($transient_timeout); 675 return false; 676 } 677 } 678 668 679 $value = get_option($transient_option); 669 680 } … … 684 695 * @param string $transient Transient name. Expected to not be SQL-escaped 685 696 * @param mixed $value Transient value. 697 * @param int $expiration Time until expiration in seconds, default 0 686 698 * @return bool False if value was not set and true if value was set. 687 699 */ 688 function set_transient($transient, $value ) {700 function set_transient($transient, $value, $expiration = 0) { 689 701 global $_wp_using_ext_object_cache, $wpdb; 690 702 691 703 if ( $_wp_using_ext_object_cache ) { 692 return wp_cache_set($transient, $value, 'transient' );704 return wp_cache_set($transient, $value, 'transient', $expiration); 693 705 } else { 706 $transient_timeout = '_transient_timeout_' . $transient; 694 707 $transient = '_transient_' . $transient; 695 708 $safe_transient = $wpdb->escape($transient); 696 if ( false === get_option( $safe_transient ) ) 697 return add_option($transient, $value, '', 'no'); 698 else 709 if ( false === get_option( $safe_transient ) ) { 710 $autoload = 'yes'; 711 if ( 0 != $expiration ) { 712 $autoload = 'no'; 713 add_option($transient_timeout, time() + $expiration, '', 'no'); 714 } 715 return add_option($transient, $value, '', $autoload); 716 } else { 717 if ( 0 != $expiration ) 718 update_option($transient_timeout, time() + $expiration); 699 719 return update_option($transient, $value); 720 } 700 721 } 701 722 } -
trunk/wp-includes/rss.php
r10512 r10603 713 713 global $wpdb; 714 714 $cache_option = 'rss_' . $this->file_name( $url ); 715 $cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts'; 716 717 set_transient($cache_option, $rss); 718 set_transient($cache_timestamp, time() ); 715 716 set_transient($cache_option, $rss, $this->MAX_AGE); 719 717 720 718 return $cache_option; … … 750 748 function check_cache ( $url ) { 751 749 $this->ERROR = ""; 752 $cache_option = $this->file_name( $url ); 753 $cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts'; 754 755 if ( $mtime = get_transient($cache_timestamp) ) { 756 // find how long ago the file was added to the cache 757 // and whether that is longer then MAX_AGE 758 $age = time() - $mtime; 759 if ( $this->MAX_AGE > $age ) { 760 // object exists and is current 750 $cache_option = 'rss_' . $this->file_name( $url ); 751 752 if ( get_transient($cache_option) ) { 753 // object exists and is current 761 754 return 'HIT'; 762 } 763 else { 764 // object exists but is old 765 return 'STALE'; 766 } 767 } 768 else { 755 } else { 769 756 // object does not exist 770 757 return 'MISS';
Note: See TracChangeset
for help on using the changeset viewer.