[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/ -> bp-activity-cache.php (source)

   1  <?php
   2  /**
   3   * Functions related to the BuddyPress Activity component and the WP Cache.
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActivityCache
   7   * @since 1.6.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Slurp up activitymeta for a specified set of activity items.
  15   *
  16   * It grabs all activitymeta associated with all of the activity items passed
  17   * in $activity_ids and adds it to the WP cache. This improves efficiency when
  18   * using querying activitymeta inline.
  19   *
  20   * @since 1.6.0
  21   *
  22   * @param int|string|array|bool $activity_ids Accepts a single activity ID, or a comma-
  23   *                                            separated list or array of activity ids.
  24   */
  25  function bp_activity_update_meta_cache( $activity_ids = false ) {
  26      $bp = buddypress();
  27  
  28      $cache_args = array(
  29          'object_ids'        => $activity_ids,
  30          'object_type'        => $bp->activity->id,
  31          'object_column'    => 'activity_id',
  32          'cache_group'      => 'activity_meta',
  33          'meta_table'        => $bp->activity->table_name_meta,
  34          'cache_key_prefix' => 'bp_activity_meta'
  35      );
  36  
  37      bp_update_meta_cache( $cache_args );
  38  }
  39  
  40  /**
  41   * Clear a cached activity item when that item is updated.
  42   *
  43   * @since 2.0.0
  44   *
  45   * @param BP_Activity_Activity $activity Activity object.
  46   */
  47  function bp_activity_clear_cache_for_activity( $activity ) {
  48      wp_cache_delete( $activity->id, 'bp_activity' );
  49      wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
  50  }
  51  add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' );
  52  
  53  /**
  54   * Clear cached data for deleted activity items.
  55   *
  56   * @since 2.0.0
  57   *
  58   * @param array $deleted_ids IDs of deleted activity items.
  59   */
  60  function bp_activity_clear_cache_for_deleted_activity( $deleted_ids ) {
  61      foreach ( (array) $deleted_ids as $deleted_id ) {
  62          wp_cache_delete( $deleted_id, 'bp_activity' );
  63      }
  64  }
  65  add_action( 'bp_activity_deleted_activities', 'bp_activity_clear_cache_for_deleted_activity' );
  66  
  67  /**
  68   * Reset cache incrementor for the Activity component.
  69   *
  70   * Called whenever an activity item is created, updated, or deleted, this
  71   * function effectively invalidates all cached results of activity queries.
  72   *
  73   * @since 2.7.0
  74   *
  75   * @return bool True on success, false on failure.
  76   */
  77  function bp_activity_reset_cache_incrementor() {
  78      $without_last_activity = bp_core_reset_incrementor( 'bp_activity' );
  79      $with_last_activity    = bp_core_reset_incrementor( 'bp_activity_with_last_activity' );
  80      return $without_last_activity && $with_last_activity;
  81  }
  82  add_action( 'bp_activity_delete',    'bp_activity_reset_cache_incrementor' );
  83  add_action( 'bp_activity_add',       'bp_activity_reset_cache_incrementor' );
  84  add_action( 'added_activity_meta',   'bp_activity_reset_cache_incrementor' );
  85  add_action( 'updated_activity_meta', 'bp_activity_reset_cache_incrementor' );
  86  add_action( 'deleted_activity_meta', 'bp_activity_reset_cache_incrementor' );


Generated: Thu Nov 14 01:01:40 2019 Cross-referenced by PHPXref 0.7.1