Make WordPress Core

Ticket #18356: 18356.2.diff

File 18356.2.diff, 1.6 KB (added by prettyboymp, 13 years ago)

switching to separate cache with shorter cache timeout

  • wp-includes/bookmark.php

     
    105105 *              separated by commas.
    106106 * 'exclude' - Default is empty string (string). Exclude other categories
    107107 *              separated by commas.
     108 * 'expiration' - Default is 600 (integer). Lifetime of result cache when ordering
     109 *              by 'rand'
    108110 *
    109111 * @since 2.1.0
    110112 * @uses $wpdb Database Object
     
    121123                'limit' => -1, 'category' => '',
    122124                'category_name' => '', 'hide_invisible' => 1,
    123125                'show_updated' => 0, 'include' => '',
    124                 'exclude' => '', 'search' => ''
     126                'exclude' => '', 'search' => '',
     127                'expire' => 60
    125128        );
    126129
    127130        $r = wp_parse_args( $args, $defaults );
    128131        extract( $r, EXTR_SKIP );
    129 
     132       
    130133        $cache = array();
    131134        $key = md5( serialize( $r ) );
    132         if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
     135        if ( $orderby == 'rand' ) {
     136                if( $results = wp_cache_get( $key, 'get_bookmarks_rand' ) )
     137                        return apply_filters('get_bookmarks', $results, $r );
     138        } elseif ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
    133139                if ( is_array($cache) && isset( $cache[ $key ] ) )
    134140                        return apply_filters('get_bookmarks', $cache[ $key ], $r );
    135141        }
     
    252258
    253259        $results = $wpdb->get_results($query);
    254260
    255         $cache[ $key ] = $results;
    256         wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
     261        if(     $orderby == 'rand()' ) {
     262                wp_cache_set( $key, $results, 'get_bookmarks_rand', $expire );
     263        } else {
     264                $cache[ $key ] = $results;
     265                wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
     266        }
    257267
    258268        return apply_filters('get_bookmarks', $results, $r);
    259269}