[buddypress-trac] [BuddyPress] #4945: Add cache support to bp_get_option()
buddypress-trac
noreply at wordpress.org
Sun Apr 21 17:58:57 UTC 2013
#4945: Add cache support to bp_get_option()
--------------------------+--------------------------
Reporter: boonebgorges | Owner: boonebgorges
Type: enhancement | Status: new
Priority: normal | Milestone: 1.8
Component: Core | Version:
Severity: normal | Keywords: 2nd-opinion
--------------------------+--------------------------
The `bp_*_option()` functions are wrappers for `*_blog_option()`. In WP
3.5, the `blog_option()` functions were rewritten to use
`switch_to_blog()`, which has dramatically reduced the performance of
these functions on certain multisite setups. As a result, our use of
`bp_get_option()` can cause significant performance problems when used on
secondary blogs.
I'd like to suggest that we cache these values. This'll ensure that, for
any given option, `switch_to_blog()` will only happen once per page load.
(This doesn't solve the performance problems in a truly general way, but
it'll help.) Something like:
{{{
function bp_get_option( $option_name, $default = '' ) {
if ( false === wp_cache_get( $option_name, 'bp' ) ) {
$value = get_blog_option( bp_get_root_blog_id(), $option_name,
$default );
wp_cache_set( $option_name, $value, 'bp' );
}
return apply_filters( 'bp_get_option', $value, $option_name, $default
);
}
}}}
We'd also need corresponding cache-busting in `bp_update_option()` and
`bp_delete_option()`.
The downside of this technique is that it'll mean double-caching (once in
the 'bp' group, once in the normal WP space). This seems pretty minor to
me, though.
An alternative route would be to extend `bp_pre_get_option()` to check
`$bp->site_options` in addition to `$bp->options`. This is a bit simpler,
but it's not persistent and so won't give the same performance benefits
when a persistent cache is used with BP.
Would like to get dev feedback before proceeding.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4945>
BuddyPress <http://buddypress.org/>
BuddyPress
More information about the buddypress-trac
mailing list