Caching BuddyPress

Support Tutorials Caching BuddyPress

Modified on May 7, 2014

You can get noticeable performance improvements by enabling Object Caching, which will improve page load times for not only BuddyPress, but many other plugins, themes and WordPress core itself.

Caching Methods Explained

Page Caching

When people think of caching, “page caching” is usually what comes to mind first. Unfortunately page caching is not a practical solution if you have BuddyPress enabled. With page caching, when a page is requested a fully assembled HTML file is generated and then served to subsequent users who visit that page (until the cache expires), dramatically reducing hits to the database. Due to the dynamic nature of BuddyPress, page caching would cause content to go stale, defeating one of the core purposes of BuddyPress – live interaction between users. You could theoretically cache pages for logged out users only. But once they are logged in your BuddyPress content would go stale and dynamic elements within the Toolbar, like Notifications, would stop updating until the page’s cache expired.

Object Caching (recommended)

Even though we are not able to cache finished pages, we can still cache a lot of the data that is used to assemble those pages via “Object Caching”. BuddyPress is built to be able to take advantage of Object Caching when you have a persistent caching plugin enabled, such as W3 Total Cache.

WordPress has an API (a set of functions) for Object Caching that allows developers to cache data used by their code. By default, WordPress allows for a form of Object Caching but its lifetime is only for a single page load. If you have a persistent caching plugin installed, you can make the object cache persist longer than a single page load which will reduce the amount of requests to your server and improve page load speed. This is what we’ll be setting up in the next section.

How to enable Object Caching

APC – (private server) (recommended)

If you are hosting your site using our recommended server setup, you can simply contact your web host and request that they install APC on your server (it’s free) and then it will be available to you as a very fast method for Object Caching. Generally you cannot install APC on a shared hosting environment. APC stores the cached values in RAM, which is why I recommend at least 2GB of RAM for ideal server performance.

Once your web host has confirmed that APC is installed and working, you will then need to enable it for WordPress with a plugin. My recommended method is with the APC Object Cache Backend plugin. This is not a true plugin, but rather a “drop-in” file. As such, you do not actually activate the plugin. You just need to copy the object-cache.php file into your /wp-content/ directory. You don’t even need to upload the actual plugin. That’s it! As long as you have APC installed on your server and have placed the file correctly, APC-powered Object Caching should now be enabled and you should begin seeing performance improvements. To confirm that it’s working, you can type this into your browser while logged in as an admin: http://www.yourdomain.com/wp-admin/plugins.php?plugin_status=dropins . It should show APC Object Cache as a drop-in.

tutorials-dropin

You can also enable APC caching using the W3 Total Cache plugin, at Performance > General Settings, under “Object Cache”. If you’re already using W3 Total Cache this may be the preferred method. If you’re not using W3 Total Cache already then I recommend the above plugin as it only requires one file to work!

File caching (shared hosting)

If you are using a shared hosting plan, APC will not be an option and you will likely be limited to file caching, where the cached values are stored in files on your web server. This will ideally result in performance gains, but there is a chance that it could actually result in a negative performance impact if your hosting environment cannot handle it. This is another reason as to why I recommend getting a good server setup and then implementing a proper caching method like APC. But if you are limited to shared hosting, you can try file caching and see if it works for you.

The best method is to install W3 Total Cache. After installing and activating the plugin, go to Performance > General Settings, and then navigate to “Object Cache”. Check the box to “Enable” the object cache. Under “Object Cache Method” it will probably only offer “Disk” as you are on shared hosting. You will see grayed out options for APC, eAccelerator, and other various options that could theoretically be installed on a private server setup. Click “Save all settings” and you have now enabled Object Caching, with the cache saving files to your disk.

tutorials-w3object

After enabling the Object Cache, you can navigate over to Performance > Object Cache to configure the cache options as necessary.

7 thoughts on “Caching BuddyPress

  1. Palobarini

    Could you make a tutorial about the best settings for W3 Total Cache and Buddypress? (preferably in shared hosting)

    1. Profile photo of Michael Eisenwasser (Admin)Michael Eisenwasser (Admin) Post author

      With W3 Total Cache, the most important setting is what I have written above in the “File caching” section. In W3TC, go to Performance > General Settings, and then navigate to “Object Cache”. Check the box to “Enable” the object cache. Under “Object Cache Method” it will probably only offer “Disk” as you are on shared hosting. Click “Save all settings” and you have now enabled Object Caching, with the cache being saved into files to your disk.

      The rest of W3TC can be mostly ignored or turned off. You don’t want any page caching with BuddyPress. You can sync assets to a CDN in W3TC settings if you want.

  2. Ray

    I tried setting up APC on my Cloud VPS 2x 2.0GHz CPU
    2048MB DDR3 RAM
    but it actually slowed the site down. Seemed to caused a few second delay before page load. My host installed it. Here is the setup. Wonder if you see anything wrong with the settings? Maybe they don’t know how to properly tune for Buddypress.
    Thanks Ray

    PHP Version 5.3.28
    Version 3.1.7
    APC Debugging Disabled
    MMAP Support Enabled
    MMAP File Mask no value
    Locking type pthread mutex Locks
    Serialization Support php
    Revision $Revision: 307215 $
    Build Date Dec 16 2013 14:38:29

    Directive Local Value Master Value
    apc.cache_by_default On On
    apc.canonicalize On On
    apc.coredump_unmap Off Off
    apc.enable_cli Off Off
    apc.enabled On On
    apc.file_md5 Off Off
    apc.file_update_protection 2 2
    apc.filters no value no value
    apc.gc_ttl 3600 3600
    apc.include_once_override Off Off
    apc.lazy_classes Off Off
    apc.lazy_functions Off Off
    apc.max_file_size 1M 1M
    apc.mmap_file_mask no value no value
    apc.num_files_hint 1000 1000
    apc.preload_path no value no value
    apc.report_autofilter Off Off
    apc.rfc1867 Off Off
    apc.rfc1867_freq 0 0
    apc.rfc1867_name APC_UPLOAD_PROGRESS APC_UPLOAD_PROGRESS
    apc.rfc1867_prefix upload_ upload_
    apc.rfc1867_ttl 3600 3600
    apc.serializer default default
    apc.shm_segments 1 1
    apc.shm_size 32M 32M
    apc.slam_defense On On
    apc.stat On On
    apc.stat_ctime Off Off
    apc.ttl 0 0
    apc.use_request_time On On
    apc.user_entries_hint 4096 4096
    apc.user_ttl 0 0
    apc.write_lock On On

    1. Profile photo of Michael Eisenwasser (Admin)Michael Eisenwasser (Admin) Post author

      Are you running BuddyPress 2.0+ ? BP made significant improvements in how it handles object caching with 2.0. Also make sure you followed the step of adding the drop-in APC plugin in WordPress, otherwise the object cache is not even being used. It should speed up the site immediately. If not, I’m not sure off hand.

  3. Ray

    I have the latest versions of everything and the drop in shows up fine. Maybe a plugin conflicting or something. I’ll have to do some further testing in my dev site. I pretty happy with the site speed without it so not a big deal.
    I’m looking forward to BuddyBoss version 4, seems to be very snappy in it’s beta form
    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>