![]() |
|
|
Article Options |
|
#16
|
||||
|
||||
|
Well, if a mod isn't written to use the datastore then enabling memcached for the datastore won't change anything. And if it is written to use the datastore then it probably doesn't need to be changed. But I suppose you could argue that if you are going to change a mod then it makes more sense to change it to use the datastore.
The following members like this post: abualjori
Last edited by kh99 : 10 Jul 2011 at 23:42. |
|
#17
|
||||
|
||||
|
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:
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. No members have liked this post.
|
||||
|
#18
|
||||
|
||||
|
FWIW I have come up with a new way to cache that doesn't have to check for a timestamp every time. This works especially nicely if you write your own memcached wrapper class.
No members have liked this post.
|
||||
|
#19
|
|||
|
|||
|
I have now updated the article in the first post with my new approach, which only makes 1 memcache call per regular pageload, and 2 when the cache needs updating. The old approach used 2 calls per pageload and 3 when the cache needed updating
No members have liked this post.
|
|
#20
|
||||
|
||||
|
Here's my latest update to the caching function to make things even easier. Simply specify a cache key and a callback function - if the data exists in the cache, it will be fetched. Otherwise, the callback will be called and the returned data will be stored in cache and returned to the user.
Usage: $cacheobj->fetch('data_key', 'some_function'); See php's documentation on call_user_func for more info on what $callback can contain. No members have liked this post.
|
||||
![]() |
«
Previous Article
|
Next Article
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
| Article Options | |
|
|
| New To Site? | Need Help? |
All times are GMT. The time now is 14:37.



