Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/09/2013 02:26:50 PM (12 years ago)
Author:
boonebgorges
Message:

When deleting an activity item, clear its metadata cache

Because of the way that the cache groups are structured, there is no simple
way to figure out which cache keys should be dropped upon deletion. Our
solution is to scan through all the keys in the 'bp' group to determine the
relevant ones. It's not particularly elegant, but this kind of cache-busting
will happen rarely (namely, when an activity item is deleted) so the overhead
is negligible.

Fixes #4804

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-cache.php

    r6342 r7051  
    3333        'cache_key_prefix' => 'bp_activity_meta'
    3434    );
    35    
     35
    3636    bp_update_meta_cache( $cache_args );
    3737}
     38
     39/**
     40 * Clear the cache for all metadata of a given activity
     41 *
     42 * @param int $activity_id
     43 */
     44function bp_activity_clear_meta_cache_for_activity( $activity_id ) {
     45    global $wp_object_cache;
     46
     47    if ( is_object( $wp_object_cache ) && ! empty( $wp_object_cache->cache['bp'] ) ) {
     48        foreach ( $wp_object_cache->cache['bp'] as $ckey => $cvalue ) {
     49            if ( 0 === strpos( $ckey, 'bp_activity_meta_' . $activity_id ) ) {
     50                wp_cache_delete( $ckey, 'bp' );
     51            }
     52        }
     53    }
     54}
Note: See TracChangeset for help on using the changeset viewer.