Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/09/2015 08:38:37 PM (10 years ago)
Author:
johnjamesjacoby
Message:

XProfile data cache group updates:

  • Switches from dynamic cache group to unique key for $user_id:$field_id.
  • Introduces bp_xprofile_get_non_cached_field_ids() as a helper, based on bp_get_non_cached_field_ids().
  • Registers bp_xprofile and bp_xprofile_data as global cache groups.
  • Updates unit tests to pass with new cache keys.

Props r-a-y. Fixes #6100. See #5733.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-cache.php

    r9318 r9336  
    1212// Exit if accessed directly
    1313if ( !defined( 'ABSPATH' ) ) exit;
     14
     15/**
     16 * Determine which xprofile fields do not have cached values for a user.
     17 *
     18 * @since BuddyPress (2.2.0)
     19 *
     20 * @param int   $user_id   User ID to check
     21 * @param array $field_ids XProfile field IDs.
     22 * @return array
     23 */
     24function bp_xprofile_get_non_cached_field_ids( $user_id = 0, $field_ids = array() ) {
     25    $uncached_fields = array();
     26
     27    foreach ( $field_ids as $field_id ) {
     28        $field_id  = (int) $field_id;
     29        $cache_key = "{$user_id}:{$field_id}";
     30        if ( false === wp_cache_get( $cache_key, 'bp_xprofile_data' ) ) {
     31            $uncached_fields[] = $field_id;
     32        }
     33    }
     34
     35    return $uncached_fields;
     36}
    1437
    1538/**
     
    4164        'group' => array(),
    4265        'field' => array(),
    43         'data'   => array(),
     66        'data'  => array(),
    4467    );
    4568
     
    171194 */
    172195function xprofile_clear_profiledata_object_cache( $data_obj ) {
    173     wp_cache_delete( $data_obj->field_id, 'bp_xprofile_data_' . $data_obj->user_id );
    174 }
    175 add_action( 'xprofile_data_after_save', 'xprofile_clear_profiledata_object_cache' );
     196    wp_cache_delete( "{$data_obj->user_id}:{$data_obj->field_id}", 'bp_xprofile_data' );
     197}
     198add_action( 'xprofile_data_after_save',   'xprofile_clear_profiledata_object_cache' );
    176199add_action( 'xprofile_data_after_delete', 'xprofile_clear_profiledata_object_cache' );
    177200
Note: See TracChangeset for help on using the changeset viewer.