buddypress/bp-activity/bp-activity-cache.php
r-a-y 95cf7fbc29 Properly set object cache for a new BP_Activity_Activity object.
This commit also renames the activity cache key and group to be
consistent with the groups component. (See r7956.)

See #5434.

git-svn-id: https://buddypress.svn.wordpress.org/trunk@7997 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2014-02-27 19:48:22 +00:00

61 lines
1.7 KiB
PHP

<?php
/**
* Functions related to the BuddyPress Activity component and the WP Cache.
*
* @since BuddyPress (1.6)
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Slurp up activitymeta for a specified set of activity items.
*
* It grabs all activitymeta associated with all of the activity items passed
* in $activity_ids and adds it to the WP cache. This improves efficiency when
* using querying activitymeta inline.
*
* @param int|str|array $activity_ids Accepts a single activity ID, or a comma-
* separated list or array of activity ids
*/
function bp_activity_update_meta_cache( $activity_ids = false ) {
global $bp;
$cache_args = array(
'object_ids' => $activity_ids,
'object_type' => $bp->activity->id,
'object_column' => 'activity_id',
'cache_group' => 'activity_meta',
'meta_table' => $bp->activity->table_name_meta,
'cache_key_prefix' => 'bp_activity_meta'
);
bp_update_meta_cache( $cache_args );
}
/**
* Clear a cached activity item when that item is updated.
*
* @since 2.0
*
* @param BP_Activity_Activity $activity
*/
function bp_activity_clear_cache_for_activity( $activity ) {
wp_cache_delete( $activity->id, 'bp_activity' );
}
add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' );
/**
* Clear cached data for deleted activity items.
*
* @since 2.0
*
* @param array $deleted_ids IDs of deleted activity items.
*/
function bp_activity_clear_cache_for_deleted_activity( $deleted_ids ) {
foreach ( (array) $deleted_ids as $deleted_id ) {
wp_cache_delete( $deleted_id, 'bp_activity' );
}
}
add_action( 'bp_activity_deleted_activities', 'bp_activity_clear_cache_for_deleted_activity' );