Changeset 9313 for trunk/src/bp-core/bp-core-cache.php
- Timestamp:
- 01/08/2015 01:24:29 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-cache.php
r8011 r9313 28 28 29 29 /** 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 */ 38 function 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 */ 60 function 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 */ 80 function 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 */ 98 function 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 } 38 103 39 104 /**
Note: See TracChangeset
for help on using the changeset viewer.