Follow vBSEO on Twitter
vBulletin Modifications
  • Forums
  • Add-Ons
  • Template Modifications
  • Styles
  • Graphics
  • Tutorials
  • Support Center
  • Register
  • vBulletin SEO

Member Log In

Site Navigation

  • Register
  • Members List
  • Social Groups
  • Search
  • Today's Posts
  • Mark Forums Read

Latest Modifications

  • [vB 3.8.4] THX - Hack for VB. 3.8.4
    By: bluedog
  • [vB 3.8.4] Cyb - Chatbox V.2.3
    By: bluedog
  • [vB 4.0.x] PHPKD - Advanced Quick...
    By: PHPKD
  • [vB 3.6.x] StopSpam
    By: flappi282
  • [vB 3.8.x] vBulletin Chat Addon for...
    By: 123flashchat

Latest Template Mods

  • [vB 4.0.x] Remove My Profile Link...
    By: Ak Worm
  • [vB 3.8.x] Images DownloadBox...
    By: cRs!MP
  • [vB 3.8.x] Adviertise Mod On Forum...
    By: MG4
  • [vB 3.8.4] Images PassWordBox...
    By: cRs!MP
  • [vB 3.8.4] Footer Follow Ups
    By: Ak Worm

Latest Styles

  • [vB 4.0.x] 4.0.3 - VB4STYLE-TWEETA...
    By: Belon
  • [vB 4.0.x] [4.0.3] vbdesigns.de...
    By: Belon
  • [vB 3.8.4] CompletevB - Skylight
    By: DreadKnight
  • [vB 3.8.3] [vB 3.8.4] Barcelona...
    By: hoiquantinhoc.com
  • [vB 3.8.3] Natures Walk by vBSkin...
    By: Chri5

Latest Graphics

  • [vB ] [anim.]Team Ranks
    By: cRs!MP
  • [vB ] Abstract Circles (3...
    By: cRs!MP
  • [vB ] PlayStation Rank Images
    By: cRs!MP
  • [vB 3.6.12] Heavy Stroked Button...
    By: Shelley
  • [vB ] Minature Ranks.
    By: Shelley
vBulletin Modifications » General vBulletin Section » vBulletin Modification Tutorials » Cache System Explanation (datastore)
Reply
Page 1 of 2 1 2 >

 

  • Thread Tools
Old 03-17-2006, 07:29 AM   #1
Ken Iovino
vBulletin Guru

Ken Iovino's Avatar

Activity Longevity
0/20 20/20
Today Posts
0/3 sssss2695
Location: Miami, Florida
Age: 27
Ken Iovino is on a distinguished road
Status: Offline Default 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?
A memory area where frequently accessed data can be stored for rapid access. (View Definitions). Basicly, you can store information into the database, and grab all this information with just using 1 query. Some may question this and say: "Isn't all information in the database retrived by queires?". Yup, all information in the database is retrived using MySQL queries, though the method used is diffrent when using the datastore system in vBulletin.
I'll show you way using the datastore is a better solution for you and the users who will use your hacks.

Datastore Method

Lets say you want to use a drop down form with 3 options to choose from. Obviously you would need to create alittle script to add, delete, and edit the information; and when you make this script. Where does the info go? Well it would go into the database. Lets call the MySQL table "dropdownoptions" with 3 fields. ID, Name, and Value.

data1.gif
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.
  • ID = (1) Name = (Dog) Value(Dog)
  • ID = (2) Name = (Cat) Value(Cat)
  • ID = (3) Name = (Cow) Value(Cow)
data2.gif

After you insert this information into the database, the next step would be to insert this info in the datastore. You can do that like this.

PHP Code:
$query = $vbulletin->db->query_read("
        SELECT *
        FROM " 
. TABLE_PREFIX . "dropdownmenu
        ORDER BY id DESC
"
);

while (
$variable = $vbulletin->db->fetch_array($query))
{
        
$variable_array[] = $variable;
}

build_datastore('dropmenu', serialize($variable_array)); 
Let me go ahead and tell you exacly what the above does. What we did was just grab all in the information in the database from the table dropdownmenu. The while() function will loop the information from the begging to the end. While it's getting all this information, It's storing it all into the variable named $variable_array.

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";}}
So now we have all our infomation stored in another area of the database, in one row. Heres a picture so you can compair it to the other ones.

data3.gif

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";
        }
}
In PHP it would look like this.
PHP Code:
$data = array(
        
'0' => array(
                
'id' => '1',
                
'name' => 'Dog',
                
'value' => 'Dog'
        
),
        
'1' => array(
                
'id' => '2',
                
'name' => 'Cat',
                
'value' => 'Cat'
        
),
        
'2' => array(
                
'id' => '3',
                
'name' => 'Cow',
                
'value' => 'Cow'
        
),
); 
So now we have the info stored, lets get it back out in a readable formate. :p This is the easy part. This is the code I use.

PHP Code:
$vbulletin->dropmenu = unserialize($vbulletin->dropmenu);
foreach (
$vbulletin->dropmenu AS $dropmenu)
{
        echo 
"(ID: "  . $dropmenu['id'] . ") (Title: " . $dropmenu['title'] . ") (Value: " . $dropmenu['title'] . ")<br />";
} 
This will print the following:
(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:
$specialtemplates = array(
        
'dropmenu'
); 
So now that you understand where the variable is coming from, we need to unserialize the data, cause it looks all ugly and weird.

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.
Ken Iovino / Escalate Media
Reply With Quote
Old 03-17-2006, 10:36 AM   #2
Arnoud
vBulletin Guru

Arnoud's Avatar

Activity Longevity
0/20 18/20
Today Posts
0/3 sssss3129
Location: Europe, Flanders
Arnoud is on a distinguished road
Send a message via MSN to Arnoud Send a message via Yahoo to Arnoud
Status: Offline Default
Very nice tut =)
Reply With Quote
Old 03-17-2006, 10:56 AM   #3
Junior
Coder

Junior's Avatar

Activity Longevity
0/20 18/20
Today Posts
0/3 ssssss809
Location: U.S.A
Age: 30
Junior is on a distinguished road
Status: Offline Default
idd very nice
Reply With Quote
Old 03-17-2006, 04:45 PM   #4
Idan
Coder
Idan's Avatar

Activity Longevity
0/20 18/20
Today Posts
0/3 sssss1484
Location: Israel
Age: 29
Idan is on a distinguished road
Status: Offline Default
yep, very nice tut indeed. :]
Regards,
Idan.

* Support will only be given via forums !
* If this post solved/aided your problem, please click "mark as aid" / "mark as solution" as explained in here
Reply With Quote
Old 03-17-2006, 11:31 PM   #5
Maxx
Coder

Maxx's Avatar

Activity Longevity
0/20 19/20
Today Posts
0/3 ssssss486
Location: U.K
Maxx is on a distinguished road
Status: Offline Default
well done on tut
Reply With Quote
Old 03-20-2006, 10:35 AM   #6
scorpio
vB Newbie

Activity Longevity
0/20 15/20
Today Posts
0/3 ssssssss2
Age: 31
scorpio is on a distinguished road
Send a message via MSN to scorpio
Status: Offline Default
many thanks for ut tutorial....
Reply With Quote
Old 04-15-2006, 03:25 PM   #7
tgreer
Guest

Activity Longevity
0/20 0/20
Today Posts
0/0 sssssssss
Default
@LiveWire:

Thanks for this, but I have some questions.

Q. I understand that the results of a SQL query must be
  1. read and stored into an array
  2. the array must be serialized into the datastore

However, WHEN must this be done? Once? In global_start, for example? Should there be a conditional to see if the data is already in the datastore? I'm curious how the original data is synchronized with the datastore.

Q. $specialtemplates kind of came out of the blue in your tutorial. What is the relationship between the datastore record and $specialtemplates? At what point would you add your datastore item/record to $specialtemplates?

Q. You explain the datastore well enough, but not caching. There is the raw data in the database. There is serialized data in the datastore table, but isn't there also a datastore caching mechanism, so that information can be retrieved from a cache without going back to the datastore table itself?

So, how can you get information from the cache vs. the datastore vs. a raw query? Or, is the datastore automatically cached, so any calls for datastore data come from the cache anyway?
Reply With Quote
Old 04-15-2006, 03:29 PM   #8
Arnoud
vBulletin Guru

Arnoud's Avatar

Activity Longevity
0/20 18/20
Today Posts
0/3 sssss3129
Location: Europe, Flanders
Arnoud is on a distinguished road
Send a message via MSN to Arnoud Send a message via Yahoo to Arnoud
Status: Offline Default
Q. $specialtemplates kind of came out of the blue in your tutorial. What is the relationship between the datastore record and $specialtemplates? At what point would you add your datastore item/record to $specialtemplates?
If I'm not mistaking, $specialtemplates gets the data from the datastore if its a custom datastore item.
Reply With Quote
Old 04-15-2006, 03:43 PM   #9
tgreer
Guest

Activity Longevity
0/20 0/20
Today Posts
0/0 sssssssss
Default
So, in terms of this tutorial...

THIS:

PHP Code:
$specialtemplates = array(
        
'dropmenu'
); 
needs to come BEFORE, THIS:

PHP Code:
$vbulletin->dropmenu = unserialize($vbulletin->dropmenu);
foreach (
$vbulletin->dropmenu AS $dropmenu)
{
        echo 
"(ID: "  . $dropmenu['id'] . ") (Title: " . $dropmenu['title'] . ") (Value: " . $dropmenu['title'] . ")<br />";
} 
??

What does putting your datastore record name/id in $specialtemplates actually do? I have a suspicion that $vbulletin->dropmenu doesn't get data from the datastore at all, but rather from the datastore cache, and that adding $dropmenu to the $specialtemplates array makes sure that it IS cached. I'm not certain... anyone willing to correct/confirm this?
Reply With Quote
Old 04-16-2006, 09:45 PM   #10
Ken Iovino
vBulletin Guru

Ken Iovino's Avatar

Activity Longevity
0/20 20/20
Today Posts
0/3 sssss2695
Location: Miami, Florida
Age: 27
Ken Iovino is on a distinguished road
Status: Offline Default
anytime you enter new information in your custom table, you have to get all the info from that table and update the datastore table with all the info.

the specialtemplates array is the name of the row your datastore is stored in. When I get back from easter dinner I'll explain it better for you. :p
Reply With Quote

Reply
Page 1 of 2 1 2 >

« [How-To] Use plugins to join default queries | [How-to] Correct the missing WOL location for the activity addon stats »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
Install system updated Ken Iovino Announcements 7 11-17-2006 05:59 PM
[REQUEST] Rating System (Possibly by TouchingVirus or ShavedApe?) figure004 vBulletin Modification Requests 4 05-22-2005 07:14 PM



All times are GMT. The time now is 05:58 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Transverse Styles
  • Top
  • Archive
  • vBSEO
  • Contact Us
LinkBack
LinkBack URL LinkBack URL
About LinkBacks About LinkBacks
Bookmark & Share
Digg this Thread! Digg this Thread!
Add Thread to del.icio.us Add Thread to del.icio.us
Bookmark in Technorati Bookmark in Technorati
Furl this Thread! Furl this Thread!