One problem with the memcached is that it can't store anything over 1Mb, and it's slow at reading out large chunks of data. Not surprisingly, I've thus found the database datastore to be better (faster) than the memcached datastore as it contains quite a bit of data, especially if you're running vbseo. Therefore, caching the smaller stuff in memcache pays off, as does the extra effort taken to modify inefficient mods.
What I've done is I added a global $vbulletin->memcache state via global.php. As such, storing data is very easy as I don't need to create an instance of the memcache object every time I want to use it.
On my board, using memcached to cache the forumhome "who's online" block cuts index.php's generation time from 0.15s to about 0.07s. This is because fully caching the listings saves hundreds of evaluations forumhome_loggedinuser. I think that in total, I cache 15 or so mods, and it really pays off. This includes my very own vb3 sidebar mod, which would otherwise take over a second to fetch the most recent data from the databse.
One piece of advice I can give everyone is that you need to understand what memcache is good at prior to using it for caching. You don't want to write mods that rely on memcache to work, or cache things for more than an hour- as then, you're probably better off just using the database to begin with.
---------------------
Regarding showgroups.php, let me start by saying that nobody ever visits that page. But if you still want to cache it, there are two approaches: you can save the result of the query and fetch it from the cache, or you can cache the entire page. Note that unless you have hundreds of users on your showgroups page, you probably won't gain much from caching.
My forum has some 1,100 users listed, and takes between 1.5 and 2 seconds to generate if you don't cache. With the cache, it's spat out in under 0.1s, of which 0.07s can be attributed to memcache (again, on my server- this varies from site to site).
Here's the rough idea, with the actual vb code cut out as required by the license:
PHP Code:
if ($cache['timeoffset'] < $cache['limit'])
{
// HTML for the output is obtained here if the cache is used
$HTML = $vbulletin->memcache->get($cache['datafile']);
}
else
{
// Execute the default script if needed
// 2 is the default location field and the one we always use in the template
// vbulletin code
// *******************************************************
// We're using GENERIC_SHELL, so populate the HTML variable
eval('$HTML = "' . fetch_template('SHOWGROUPS') . '";');
// Write the resulting HTML to the cache
$vbulletin->memcache->set($cache['datafile'],$HTML,MEMCACHE_COMPRESSED);
// Write the time of the caching
$vbulletin->memcache->set($cache['timefile'],TIMENOW);
}
I'm pretty sure I modified my SHOWGROUPS template in order to be able to do full HTML caching, but I forget.
---------------------
Another idea for those who want to be even more efficient is to get both the time and data in a single $memcache->get call, which will save you 1 get per pageload at the expense of fetching unecessary data if it turns out the cache need to be updated. You can also try playing around with $memcache->add, although I've found the behavior of this to be somewhat unpredictable.