Make WordPress Core


Ignore:
Timestamp:
11/23/2006 05:04:05 PM (20 years ago)
Author:
matt
Message:

Caching for get_bookmarks

File:
1 edited

Legend:

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

    r4495 r4520  
    2020// Deprecate
    2121function get_link($bookmark_id, $output = OBJECT) {
    22         return get_bookmark($bookmark_id, $output);
     22        return get_bookmark($bookmark_id, $output);     
    2323}
    2424
    … …  
    3535        $r = array_merge($defaults, $r);
    3636        extract($r);
     37
     38        $key = md5( serialize( $r ) );
     39        if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) )
     40                if ( isset( $cache[ $key ] ) )
     41                        return apply_filters('get_bookmarks', $cache[ $key ], $r );
    3742
    3843        $inclusions = '';
    … …  
    5156                }
    5257        }
    53         if (!empty($inclusions))
     58        if (!empty($inclusions)) 
    5459                $inclusions .= ')';
    5560
    … …  
    6671                }
    6772        }
    68         if (!empty($exclusions))
     73        if (!empty($exclusions)) 
    6974                $exclusions .= ')';
    70 
     75               
    7176        if ( ! empty($category_name) ) {
    7277                if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") )
    … …  
    8893        }
    8994        if (!empty($category_query)) {
    90                 $category_query .= ')';
     95                $category_query .= ')'; 
    9196                $join = " LEFT JOIN $wpdb->link2cat ON ($wpdb->links.link_id = $wpdb->link2cat.link_id) ";
    9297        }
    … …  
    129134
    130135        $results = $wpdb->get_results($query);
     136
     137        $cache[ $key ] = $results;
     138        wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
     139
    131140        return apply_filters('get_bookmarks', $results, $r);
    132141}
    133142
     143function delete_get_bookmark_cache() {
     144        wp_cache_delete( 'get_bookmarks', 'bookmark' );
     145}
     146add_action( 'add_link', 'delete_get_bookmark_cache' );
     147add_action( 'edit_link', 'delete_get_bookmark_cache' );
     148add_action( 'delete_link', 'delete_get_bookmark_cache' );
     149
    134150?>
Note: See TracChangeset for help on using the changeset viewer.