Changeset 9887 for trunk/src/bp-notifications/bp-notifications-cache.php
- Timestamp:
- 05/21/2015 07:56:59 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-cache.php
r9819 r9887 32 32 33 33 /** 34 * Clear all notifications cache for a given user ID 35 * 36 * @since BuddyPress (2.3.0) 37 * 38 * @param int $user_id The user ID's cache to clear 39 */ 40 function bp_notifications_clear_all_for_user_cache( $user_id = 0 ) { 41 wp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' ); 42 } 43 44 /** 34 45 * Invalidate 'all_for_user_' cache when saving. 35 46 * … … 39 50 */ 40 51 function bp_notifications_clear_all_for_user_cache_after_save( BP_Notifications_Notification $n ) { 41 wp_cache_delete( 'all_for_user_' . $n->user_id, 'bp_notifications');52 bp_notifications_clear_all_for_user_cache( $n->user_id ); 42 53 } 43 54 add_action( 'bp_notification_after_save', 'bp_notifications_clear_all_for_user_cache_after_save' ); … … 51 62 */ 52 63 function bp_notifications_clear_all_for_user_cache_before_delete( $args ) { 64 53 65 // Pull up a list of items matching the args (those about te be deleted) 54 66 $ns = BP_Notifications_Notification::get( $args ); … … 59 71 } 60 72 61 foreach ( array_unique( $user_ids ) as $user_id ) { 62 wp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' ); 73 $user_ids = array_unique( $user_ids ); 74 foreach ( $user_ids as $user_id ) { 75 bp_notifications_clear_all_for_user_cache( $user_id ); 63 76 } 64 77 } 65 78 add_action( 'bp_notification_before_delete', 'bp_notifications_clear_all_for_user_cache_before_delete' ); 79 80 /** 81 * Invalidates 'all_for_user_' cache when updating. 82 * 83 * @since BuddyPress (2.3.0) 84 * 85 * @param array $update_args See BP_Notifications_Notification::update() for description. 86 * @param array $where_args See BP_Notifications_Notification::update() for description. 87 */ 88 function bp_notifications_clear_all_for_user_cache_before_update( $update_args, $where_args ) { 89 90 // User ID is passed in where arugments 91 if ( ! empty( $where_args['user_id'] ) ) { 92 bp_notifications_clear_all_for_user_cache( $where_args['user_id'] ); 93 94 // Get user ID from Notification ID 95 } elseif ( ! empty( $where_args['id'] ) ) { 96 $n = bp_notifications_get_notification( $where_args['id'] ); 97 bp_notifications_clear_all_for_user_cache( $n->user_id ); 98 } 99 } 100 add_action( 'bp_notification_before_update', 'bp_notifications_clear_all_for_user_cache_before_update', 10, 2 );
Note: See TracChangeset
for help on using the changeset viewer.