The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Cache System Explanation (datastore)
I'm going to try and explain the datastore system used in vBulltin. This tutorial is based around users who are already familar with PHP and MySQL. What is Cache? I'll show you way using the datastore is a better solution for you and the users who will use your hacks. Attachment 44423 Now everytime you add, edit, or delete your information, it will be changed in the database. Here is an example of the database tree. We have 3 rows of information. Attachment 44424 PHP Code:
Then you need to use the function called build_datastore(). This function requires the following. build_datastore(1, 2). #1 is the name of your datastore item, and number two is the serialize information to store. This function will create a new datastore item with the name and all your info. The serialize info will look like this... Code:
a:3:{i:0;a:3:{s:2:"id";s:1:"1";s:4:"name";s:3:"Dog";s:5:"value";s:3:"Dog";}i:1;a:3:{s:2:"id";s:1:"2";s:4:"name";s:3:"Cat";s:5:"value";s:3:"Cat";}i:2;a:3:{s:2:"id";s:1:"3";s:4:"name";s:3:"Cow";s:5:"value";s:3:"Cow";}} Attachment 44425 Don't let the serialize data freak you out. You don't really NEED to read that data. Though I kinda like doing it, so I'll break it down alittle for you. Here is a tree of the serialize data. Code:
a:3:{ i:0; a:3:{ s:2:"id";s:1:"1"; s:4:"name";s:3:"Dog"; s:5:"value";s:3:"Dog"; } i:1; a:3:{ s:2:"id";s:1:"2"; s:4:"name";s:3:"Cat"; s:5:"value";s:3:"Cat"; } i:2; a:3:{ s:2:"id";s:1:"3"; s:4:"name";s:3:"Cow"; s:5:"value";s:3:"Cow"; } } PHP Code:
PHP Code:
(ID: 1) (Title: Dog) (Value: Dog) (ID: 2) (Title: Cat) (Value: Cat) (ID: 3) (Title: Cow) (Value: Cow) What your doing is simple. The variable $vbulletin->dropmenu holds the information though it's still serialize. The reason why $vbulletin->dropmenu is the variable is because you need to tell vBulletin which datastore row to get. In this case it is dropmenu because remember we stored it in there like this: build_datastore('dropmenu', serialize($variable_array)); Now in order for vBulletin to know about that specific row, you need to add it to the $specialtemplates array. Example: PHP Code:
So $vbulletin->dropmenu = unserialize($vbulletin->dropmenu); baiscly gets the serialize info and unserialize's it using the function called unserialize() Once that is finished you want to loop the info using a foreach() function. foreach ($vbulletin->dropmenu AS $dropmenu). Doing that is storing the array info into $dropmenu and you can get each one by using the following vaiables. $dropmenu['id'], $dropmenu['title'], and $dropmenu['value']. The reason why this is better is because vBulletin allready runs one global query to get all the datatore information. So instead of running a query everytime you want to get the drop down information, you just get it from the datastore and save that query. Some may think this is kinda extreme when you can just run a query, though as your site grows; you want to save as many queires as possiable. If your interested in saving queries and bandwidth. I would suggest taking a look at Trigunflames profile. He has released many hacks to help in these areas. Copyright ?2004-2006 vBHackers.com All Rights Reserved. This tutorial may not be redistributed in whole or significant part. |
#32
|
|||
|
|||
Can you please share it with us. I am so tired of trying to make this work. It has been 5 days but I couldn't cache anything yet. It would be great to know how to cache sql queries.
|
#33
|
||||
|
||||
What was different from the posted solutions?
|
#34
|
||||
|
||||
i'm still trying to figure out how to export this entire thing (with all my crons/ phrases etc) but no one is helping me out on .com
http://www.vbulletin.com/forum/showthread.php?t=274552 otherwise, i'd just post my entire product. basically, this is what i did. 1) I made a cron job to populate a table from live post/thread table data. (Perhaps this table is useless now altogether, but i like having a table i can reference during testing. next version probably won't include this cache_ table at all) Code:
<?php
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
//clean up...
$vbulletin->db->query_write('TRUNCATE TABLE ' . TABLE_PREFIX . 'cache_activetopics');
$vbulletin->db->query_write('insert into ' . TABLE_PREFIX . 'cache_activetopics
/// my big select query here
');
// now, this loads that new data into an array, which is then shoved into the build datastore function:
$query = $vbulletin->db->query_read('SELECT * from ' . TABLE_PREFIX . 'cache_activetopics');
while ($variable = $vbulletin->db->fetch_array($query))
{
$variable_array[] = $variable;
}
build_datastore('skm_active_cache', serialize($variable_array), true);
log_cron_action('', $nextitem, 1);
?>
Set up the cron job to run this script as you like. Run it once manually to make sure you have data in the datastore row. there will actually be a row with the name skm_active_cache in the datastore table. 2) from there, i have 4 plugins in my product Quote:
it contains a simple line: Code:
$globaltemplates[] = 'skm_activethreads24_forumhome'; This file pulls the datastore row into memory: Code:
$datastore_fetch[] = "'skm_active_cache'"; c) forumhome_complete hook : parse the data and print it to the template step. obviously, forumhome_complete should match the area you are trying to hook into. in my case, it was on the forum home. Code:
foreach ($vbulletin->skm_active_cache AS $mycache) { $output['threadid'] = $mycache['tid']; eval("\$mythreadbits .= \"".fetch_template('skm_activethreads24_forumhome')."\";"); } Code:
<a href="showthread.php?t=$output[threadid]&goto=newpost"> That's about it. basically, you need to fill the datastore with your query, and pull with a foreach of the array once the data has been initialized. |
#35
|
|||
|
|||
Hello,
Thank you so much for your tutorial. This was exactly what I was looking for. I write my own products/plugins (our forums is huge) and I was wondering how to cache stuff around. However I faced one problem: I couldn't read data back. The solution was to add a "1" parameter on the store command: build_datastore('name',serialize($variable),1); When retrieving you don't need to "unserialize" it. Also I was trying to call my cached array inside a class that hasn't had $vbulletin as a global variable, so I needed to add: global $vbulletin; On the top of my plugin. And I also needed to add a plugin for the init_startup hook, adding: $datastore_fetch[]="'name'"; I hope this feedback helps other coders. Cheers, Gabriel. |
#36
|
|||
|
|||
This should really be added to the first post. Took forever to figure this out.
|
#37
|
|||
|
|||
Is there a datastore per user?
|
#38
|
||||
|
||||
If you have this, now How can I delete one of the data (red below) ???
Code:
a:3:{ i:0; a:3:{ s:2:"id";s:1:"1"; s:4:"name";s:3:"Dog"; s:5:"value";s:3:"Dog"; } i:1; a:3:{ s:2:"id";s:1:"2"; s:4:"name";s:3:"Cat"; s:5:"value";s:3:"Cat"; } i:2; a:3:{ s:2:"id";s:1:"3"; s:4:"name";s:3:"Cow"; s:5:"value";s:3:"Cow"; } } |
#39
|
|||
|
|||
it could be possible to fetch more than 1 value
for example (ID: 1) (Title: Dog) (Value: Dog , dog2, dog4) and be able to delete dog4 (ID: 1) (Title: Dog) (Value: Dog , dog2) or add more any ideas? maybe first check if its empty or :S? |
#40
|
|||
|
|||
Hello,
I seem to be unable to persist the values in datastore. Variables built and stored to datastore in global_start plugin are lost in subsequent requests. I wish the purpose, usage, lifecycle, limitations and performance of datastore would be discussed more in the article. -Pete |
#41
|
||||
|
||||
Quote:
That's what i was missing |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|