Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/19/2009 01:35:32 PM (16 years ago)
Author:
apeatling
Message:

Added basic object caching support ready for the first release. This will cut the number of database calls and load by 3x. Add define( 'WP_CACHE', true ); to you wp-config.php and drop object-cache.php into /wp-content/ to enable.

A good file based object cache is available here:
http://neosmart.net/dl.php?id=14

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-templatetags.php

    r1224 r1238  
    1717
    1818    function bp_xprofile_template($user_id) {
    19         $this->groups = BP_XProfile_Group::get_all(true);
     19        if ( !$this->groups = wp_cache_get( 'xprofile_groups', 'bp' ) ) {
     20            $this->groups = BP_XProfile_Group::get_all(true);
     21            wp_cache_set( 'xprofile_groups', $this->groups, 'bp' );
     22        }
     23
    2024        $this->group_count = count($this->groups);
    2125        $this->user_id = $user_id;
     
    3539        $this->field_count = count($this->group->fields);
    3640       
    37         for ( $i = 0; $i < $this->field_count; $i++ ) {
    38             $this->group->fields[$i] = new BP_XProfile_Field( $this->group->fields[$i]->id, $this->user_id );   
    39         }
     41        if ( !$fields = wp_cache_get( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, 'bp' ) ) {
     42            for ( $i = 0; $i < $this->field_count; $i++ ) {
     43                $field = new BP_XProfile_Field( $this->group->fields[$i]->id, $this->user_id );
     44                $fields[$i] = $field;
     45            }
     46           
     47            wp_cache_set( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, $fields, 'bp' );
     48        }
     49       
     50        $this->group->fields = $fields;
    4051       
    4152        return $this->group;
     
    227238    global $bp, $group_name;
    228239   
    229     $groups = BP_XProfile_Group::get_all();
    230    
     240    if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) {
     241        $groups = BP_XProfile_Group::get_all();
     242        wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' );
     243    }
     244
    231245    if ( empty( $group_name ) )
    232246        $group_name = bp_profile_group_name(false);
     
    253267        $group_id = 1;
    254268   
    255     $group = new BP_XProfile_Group($group_id);
     269    if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
     270        $group = new BP_XProfile_Group($group_id);
     271        wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
     272    }
    256273   
    257274    if ( $echo ) {
Note: See TracChangeset for help on using the changeset viewer.