WordPress.org

Make WordPress Core

Changeset 10603


Ignore:
Timestamp:
02/20/2009 02:23:11 AM (9 years ago)
Author:
ryan
Message:

Add expiration for transients

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r10593 r10603  
    666666    } else {
    667667        $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
    668679        $value = get_option($transient_option);
    669680    }
     
    684695 * @param string $transient Transient name. Expected to not be SQL-escaped
    685696 * @param mixed $value Transient value.
     697 * @param int $expiration Time until expiration in seconds, default 0
    686698 * @return bool False if value was not set and true if value was set.
    687699 */
    688 function set_transient($transient, $value) {
     700function set_transient($transient, $value, $expiration = 0) {
    689701    global $_wp_using_ext_object_cache, $wpdb;
    690702
    691703    if ( $_wp_using_ext_object_cache ) {
    692         return wp_cache_set($transient, $value, 'transient');
     704        return wp_cache_set($transient, $value, 'transient', $expiration);
    693705    } else {
     706        $transient_timeout = '_transient_timeout_' . $transient;
    694707        $transient = '_transient_' . $transient;
    695708        $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);
    699719            return update_option($transient, $value);
     720        }
    700721    }
    701722}
  • trunk/wp-includes/rss.php

    r10512 r10603  
    713713        global $wpdb;
    714714        $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);
    719717
    720718        return $cache_option;
     
    750748    function check_cache ( $url ) {
    751749        $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
    761754                return 'HIT';
    762             }
    763             else {
    764                 // object exists but is old
    765                 return 'STALE';
    766             }
    767         }
    768         else {
     755        } else {
    769756            // object does not exist
    770757            return 'MISS';
Note: See TracChangeset for help on using the changeset viewer.