PDA

View Full Version : Template caching doesn't seem to be working


findingpeace
08-18-2014, 03:14 AM
In my config.php file, I have the following line enabled:

$config['Datastore']['class'] = 'vB_Datastore_XCache';

Server shows xcache installed:

PHP 5.4.20 (cli) (built: Oct 14 2013 16:02:24)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with XCache v3.0.3, Copyright (c) 2005-2013, by mOo
with the ionCube PHP Loader v4.4.1, Copyright (c) 2002-2013, by ionCube Ltd.
with XCache Cacher v3.0.3, Copyright (c) 2005-2013, by mOo

Caching isn't disabled in ACP-->Options-->Server/Optimization Options.

So here's the problem - I have many templates cached via plugins in the cache_templates hook like so:

$cache[] = 'mytemplate';

But these templates aren't caching at all. For example, I have the "DBTech Thank You Hack" installed (shows recent "Thanks" in a memberinfo tab), so I tried refreshing on the memberinfo page every few seconds, but the debugger still shows the same number of queries. I don't have any new "Thanks" but it's still running 20 big queries on the same 20 recent members who thanked me. All just to get their username and post link (which it should already have in cache from my refresh moments ago!)

Every single refresh, it runs this query 20 times:

SELECT
userfield.*, usertextfield.*, user.*, UNIX_TIMESTAMP(passworddate) AS passworddate, user.languageid AS saved_languageid,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight, customavatar.height_thumb AS avheight_thumb, customavatar.width_thumb AS avwidth_thumb, customavatar.filedata_thumb
, bu.bloguserid, bu.entries, bu.options AS blog_options, bu.subscribeown AS blog_subscribeown, bu.memberids, bu.memberblogids,
bu.subscribeothers AS blog_subscribeothers, bu.title AS blog_title, bu.description AS blog_description, bu.allowsmilie AS blog_allowsmilie, bu.draft AS blog_draft, bu.pending AS blog_pending, bu.options_member, bu.options_guest, bu.options_buddy, bu.options_ignore, bu.uncatentries, bu.moderation AS blog_moderation, bu.deleted AS blog_deleted, bu.akismet_key AS blog_akismet_key, isblogmoderator, bu.comments_moderation AS blog_comments_moderation, bu.lastblog, bu.lastblogid, bu.lastblogtitle, bu.categorycache, bu.tagcloud, bu.sidebar, bu.custompages, bu.customblocks, blockparsed.blocktext, 1 AS blogstyleid, blog_usercsscache.csscolors AS blog_csscolors, blog_usercsscache.cachedcss AS blog_cachedcss, IF(blog_usercsscache.cachedcss IS NULL, 0, 1) AS blog_hascachedcss, blog_usercsscache.buildpermissions AS blog_cssbuildpermissions, gm.permissions AS grouppermissions, ignored.relationid AS ignoreid, buddy.relationid AS buddyid, IF(blog_subscribeuser.blogsubscribeuserid, 1, 0) AS blogsubscribed, customprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline, customprofilepic.width AS ppwidth, customprofilepic.height AS ppheight
FROM vbuser AS user
LEFT JOIN vbuserfield AS userfield ON (user.userid = userfield.userid)
LEFT JOIN vbusertextfield AS usertextfield ON (usertextfield.userid = user.userid) LEFT JOIN vbavatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN vbcustomavatar AS customavatar ON (customavatar.userid = user.userid)

LEFT JOIN vbblog_user AS bu ON (bu.bloguserid = user.userid)
LEFT JOIN vbblog_custom_block_parsed AS blockparsed ON (blockparsed.userid = user.userid AND blockparsed.styleid = 1 AND blockparsed.languageid = 1)
LEFT JOIN vbuserlist AS ignored ON (ignored.userid = user.userid AND ignored.relationid = 1 AND ignored.type = 'ignore')
LEFT JOIN vbuserlist AS buddy ON (buddy.userid = user.userid AND buddy.relationid = 1 AND buddy.type = 'buddy')
LEFT JOIN vbblog_groupmembership AS gm ON (user.userid = gm.bloguserid AND gm.userid = 1)
LEFT JOIN vbblog_subscribeuser AS blog_subscribeuser ON (user.userid = blog_subscribeuser.bloguserid AND blog_subscribeuser.userid = 1)
LEFT JOIN vbblog_usercsscache AS blog_usercsscache ON (user.userid = blog_usercsscache.userid)
LEFT JOIN vbcustomprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid)
WHERE user.userid = #### LIMIT 1

Add on the tags/quotes mod, and my member info page gets REALLY slow.

Shouldn't template caching ultimately result in fewer queries every few reloads?

Thanks!

ForceHSS
08-18-2014, 04:19 AM
Have you checked with your host to make sure it really is installed also check server error logs

Zachery
08-18-2014, 06:00 AM
That query isn't to fetch a template, its a query to fetch data.

The datastore doesn't cache templates either.

The cache doesn't cache the page output either.

I don't think the cache you're looking at does what you think it does.

CAG CheechDogg
08-18-2014, 06:06 AM
Hmmm..interesting .....

findingpeace
08-18-2014, 11:02 AM
Thanks everyone! This is very interesting. I'm trying to learn a lot more about optimizing vBulletin, and I've come pretty far on most pages! Cut down load times from 2 seconds to .5 seconds (and CMS from 8 seconds to .7 seconds). A lot of these had to do with old poorly designed mods.

But this memberinfo / template caching has me confused. I guess my question here would be, how can I just keep that fetch data query cached for a few minutes, so it doesn't need to reload every time?

I figured out that query seems to be coming from fetch_avatar_url, which I use to show the avatar of the "Thanker". Why in the world does it need all of that data in the query? Can't it just grab the avatar info? And again, same question as above, how can I keep this information cached so it doesn't run the query every time?

For example, when I look at the queries on a regular posting thread, I don't see that fetch data query run once. And yet magically, I still see everyone's avatar and username on the page!

--------------- Added 1408372276 at 1408372276 ---------------

Ah bummer. Found the problem in functions_user.php:

function fetch_avatar_url($userid, $thumb = false)
/*
Changed the code to only use the cache for $avatarinfo.
The problem with caching the url as well is that if you have already called
this function with $thumb = false you cannot then call it with $thumb = true (or vice versa).
*/

C'mon vb developers!

As a solution, I will rewrite this as two functions, one for thumbnail, one for non-thumbnail. That way both can cache.