WordPress.org

Make WordPress Core

Changeset 4519


Ignore:
Timestamp:
11/23/2006 04:52:42 PM (12 years ago)
Author:
matt
Message:

Caching for get_categories

File:
1 edited

Legend:

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

    r4219 r4519  
    3030    $r['number'] = (int) $r['number'];
    3131    extract($r);
     32
     33    $key = md5( serialize( $r ) );
     34    if ( $cache = wp_cache_get( 'get_categories', 'category' ) )
     35        if ( isset( $cache[ $key ] ) )
     36            return $cache[ $key ];
    3237
    3338    $where = 'cat_ID > 0';
     
    120125    reset ( $categories );
    121126
     127    $cache[ $key ] = $categories;
     128    wp_cache_set( 'get_categories', $cache, 'category' );
     129
    122130    return apply_filters('get_categories', $categories, $r);
    123131}
     132
     133function delete_get_categories_cache() {
     134    wp_cache_delete('get_categories', 'category');
     135}
     136add_action( 'wp_insert_post', 'delete_get_categories_cache' );
     137add_action( 'edit_category', 'delete_get_categories_cache' );
     138add_action( 'add_category', 'delete_get_categories_cache' );
     139add_action( 'delete_category', 'delete_get_categories_cache' );
    124140
    125141// Retrieves category data given a category ID or category object.
Note: See TracChangeset for help on using the changeset viewer.