Skip to:
Content

BuddyPress.org

Changeset 9313


Ignore:
Timestamp:
01/08/2015 01:24:29 AM (6 years ago)
Author:
johnjamesjacoby
Message:

Deprecate bp_core_add_global_group() and move it to BP_Core::setup_cache_groups().

Also introduce bp_cache_get/set/delete functions for appending the network ID to keys in global cache groups.

See #5733.

Location:
trunk/src/bp-core
Files:
3 edited

Legend:

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

    r8011 r9313  
    2828
    2929/**
    30  * Add 'bp' to global group of network wide cachable objects.
    31  */
    32 function bp_core_add_global_group() {
    33     if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    34         wp_cache_add_global_groups( array( 'bp' ) );
    35     }
    36 }
    37 add_action( 'bp_loaded', 'bp_core_add_global_group' );
     30 * Get the root blog cache key, used by our wrapper functions to differentiate
     31 * which blog to store our cached data in.
     32 *
     33 * @since BuddyPress (2.2.0)
     34 *
     35 * @param  string $key
     36 * @return string
     37 */
     38function bp_get_root_blog_cache_key( $key = '' ) {
     39    $root_blog_id = bp_get_root_blog_id();
     40    return "{$root_blog_id}:{$key}";
     41}
     42
     43/**
     44 * Retrieves the cache contents from the cache by key and group.
     45 *
     46 * @since BuddyPress (2.2.0)
     47 *
     48 * @uses wp_cache_get()
     49 * @see WP_Object_Cache::get()
     50 *
     51 * @param  int|string $key   What the contents in the cache are called
     52 * @param  string     $group Where the cache contents are grouped
     53 * @param  bool       $force Whether to force an update of the local cache from
     54 *                           the persistent cache (default is false)
     55 * @param  &bool      $found Whether key was found in the cache. Disambiguates a
     56 *                           return of false, a storable value.
     57 * @return bool|mixed        False on failure to retrieve contents or the cache
     58 *                           contents on success
     59 */
     60function bp_cache_get( $key, $group = '', $force = false, &$found = null ) {
     61    $cache_key = bp_get_root_blog_cache_key( $key );
     62
     63    return wp_cache_get( $cache_key, $group, $force, $found );
     64}
     65
     66/**
     67 * Saves the data to the cache.
     68 *
     69 * @since BuddyPress (2.2.0)
     70 *
     71 * @uses wp_cache_set()
     72 * @see WP_Object_Cache::set()
     73 *
     74 * @param  int|string $key    What to call the contents in the cache
     75 * @param  mixed      $data   The contents to store in the cache
     76 * @param  string     $group  Where to group the cache contents
     77 * @param  int        $expire When to expire the cache contents
     78 * @return bool               False on failure, true on success
     79 */
     80function bp_cache_set( $key, $data, $group = '', $expire = 0 ) {
     81    $cache_key = bp_get_root_blog_cache_key( $key );
     82
     83    return wp_cache_set( $cache_key, $data, $group, $expire );
     84}
     85
     86/**
     87 * Removes the cache contents matching key and group.
     88 *
     89 * @since BuddyPress (2.2.0)
     90 *
     91 * @uses wp_cache_delete()
     92 * @see WP_Object_Cache::delete()
     93 *
     94 * @param  int|string $key   What the contents in the cache are called
     95 * @param  string     $group Where the cache contents are grouped
     96 * @return bool              True on successful removal, false on failure
     97 */
     98function bp_cache_delete( $key, $group = '' ) {
     99    $cache_key = bp_get_root_blog_cache_key( $key );
     100
     101    return wp_cache_delete( $cache_key, $group );
     102}
    38103
    39104/**
  • trunk/src/bp-core/bp-core-loader.php

    r9308 r9313  
    252252        }
    253253    }
     254
     255    /**
     256     * Setup cache groups
     257     *
     258     * @since BuddyPress (2.2.0)
     259     */
     260    public function setup_cache_groups() {
     261
     262        // Global groups
     263        wp_cache_add_global_groups( array(
     264            'bp'
     265        ) );
     266
     267        parent::setup_cache_groups();
     268    }
    254269}
    255270
  • trunk/src/bp-core/deprecated/2.2.php

    r9273 r9313  
    9595    return bp_members_format_activity_action_new_member( $action, $activity );
    9696}
     97
     98/**
     99 * Add 'bp' to global group of network wide cachable objects.
     100 *
     101 * @since BuddyPress (1.1)
     102 * @deprecated BuddyPress (2.2.0)
     103 */
     104function bp_core_add_global_group() {
     105    _deprecated_function( __FUNCTION__, '2.2', 'This function cas no replacement' );
     106}
Note: See TracChangeset for help on using the changeset viewer.