WordPress.org

Make WordPress Core

Changeset 12128


Ignore:
Timestamp:
10/29/2009 09:53:57 PM (11 years ago)
Author:
ryan
Message:

Introduce get/set/delete_site_transient(). Make theme_roots a site transient.

Location:
trunk
Files:
3 edited

Legend:

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

    r12052 r12128  
    31913191}
    31923192
     3193function delete_site_option( $key ) {
     3194    $result = delete_option($key);
     3195    do_action( "delete_site_option_{$key}", $key );
     3196    return $result;
     3197}
     3198
    31933199// expects $key, $value not to be SQL escaped
    31943200function update_site_option( $key, $value ) {
     
    31983204    do_action( "update_site_option_{$key}", $key, $value );
    31993205    return $result;
     3206}
     3207
     3208/**
     3209 * Delete a site transient
     3210 *
     3211 * @since 2.890
     3212 * @package WordPress
     3213 * @subpackage Transient
     3214 *
     3215 * @param string $transient Transient name. Expected to not be SQL-escaped
     3216 * @return bool true if successful, false otherwise
     3217 */
     3218function delete_site_transient($transient) {
     3219    global $_wp_using_ext_object_cache, $wpdb;
     3220
     3221    if ( $_wp_using_ext_object_cache ) {
     3222        return wp_cache_delete($transient, 'site-transient');
     3223    } else {
     3224        $transient = '_site_transient_' . esc_sql($transient);
     3225        return delete_site_option($transient);
     3226    }
     3227}
     3228
     3229/**
     3230 * Get the value of a site transient
     3231 *
     3232 * If the transient does not exist or does not have a value, then the return value
     3233 * will be false.
     3234 *
     3235 * @since 2.9.0
     3236 * @package WordPress
     3237 * @subpackage Transient
     3238 *
     3239 * @param string $transient Transient name. Expected to not be SQL-escaped
     3240 * @return mixed Value of transient
     3241 */
     3242function get_site_transient($transient) {
     3243    global $_wp_using_ext_object_cache, $wpdb;
     3244
     3245    $pre = apply_filters( 'pre_site_transient_' . $transient, false );
     3246    if ( false !== $pre )
     3247        return $pre;
     3248
     3249    if ( $_wp_using_ext_object_cache ) {
     3250        $value = wp_cache_get($transient, 'site-transient');
     3251    } else {
     3252        $transient_option = '_site_transient_' . esc_sql($transient);
     3253        $transient_timeout = '_site_transient_timeout_' . esc_sql($transient);
     3254        if ( get_site_option($transient_timeout) < time() ) {
     3255            delete_site_option($transient_option);
     3256            delete_site_option($transient_timeout);
     3257            return false;
     3258        }
     3259
     3260        $value = get_site_option($transient_option);
     3261    }
     3262
     3263    return apply_filters('site_transient_' . $transient, $value);
     3264}
     3265
     3266/**
     3267 * Set/update the value of a site transient
     3268 *
     3269 * You do not need to serialize values, if the value needs to be serialize, then
     3270 * it will be serialized before it is set.
     3271 *
     3272 * @since 2.9.0
     3273 * @package WordPress
     3274 * @subpackage Transient
     3275 *
     3276 * @param string $transient Transient name. Expected to not be SQL-escaped
     3277 * @param mixed $value Transient value.
     3278 * @param int $expiration Time until expiration in seconds, default 0
     3279 * @return bool False if value was not set and true if value was set.
     3280 */
     3281function set_site_transient($transient, $value, $expiration = 0) {
     3282    global $_wp_using_ext_object_cache, $wpdb;
     3283
     3284    if ( $_wp_using_ext_object_cache ) {
     3285        return wp_cache_set($transient, $value, 'site-transient', $expiration);
     3286    } else {
     3287        $transient_timeout = '_site_transient_timeout_' . $transient;
     3288        $transient = '_site_transient_' . $transient;
     3289        $safe_transient = esc_sql($transient);
     3290        if ( false === get_site_option( $safe_transient ) ) {
     3291            if ( 0 != $expiration )
     3292                add_site_option($transient_timeout, time() + $expiration);
     3293            return add_site_option($transient, $value);
     3294        } else {
     3295            if ( 0 != $expiration )
     3296                update_site_option($transient_timeout, time() + $expiration);
     3297            return update_site_option($transient, $value);
     3298        }
     3299    }
    32003300}
    32013301
  • trunk/wp-includes/theme.php

    r12124 r12128  
    399399
    400400    /* Store theme roots in the DB */
    401     if ( get_transient( 'theme_roots' ) != $theme_roots )
    402         set_transient( 'theme_roots', $theme_roots, 7200 ); // cache for two hours
     401    if ( get_site_transient( 'theme_roots' ) != $theme_roots )
     402        set_site_transient( 'theme_roots', $theme_roots, 7200 ); // cache for two hours
    403403
    404404    foreach ( (array) $theme_names as $theme_name ) {
     
    427427 */
    428428function get_theme_roots() {
    429     $theme_roots = get_transient( 'theme_roots' );
     429    $theme_roots = get_site_transient( 'theme_roots' );
    430430    if ( false === $theme_roots ) {
    431431        get_themes();
    432         $theme_roots = get_transient( 'theme_roots' ); // this is set in get_theme()
     432        $theme_roots = get_site_transient( 'theme_roots' ); // this is set in get_theme()
    433433    }
    434434    return $theme_roots;
  • trunk/wp-settings.php

    r11966 r12128  
    305305wp_cache_init();
    306306if ( function_exists('wp_cache_add_global_groups') ) {
    307     wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta'));
     307    wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient'));
    308308    wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
    309309}
Note: See TracChangeset for help on using the changeset viewer.