vBulletin Modifications

Cache System Explanation (datastore)

Welcome to vBHackers.com! - vBHackers Updates:

Go Back   vBulletin Modifications > General vBulletin Section > General vBulletin Support > vBulletin Modification Tutorials

Reply
 
LinkBack Thread Tools
Old 03-17-2006, 04:29 AM   #1
Ken Iovino
Founder
Ken Iovino's Avatar
Join Date: Mar 2004
Real Name: Ken Iovino
Location: Miami, Florida
Ken Iovino is on a distinguished road

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.

You must first be a registered member to view any code.
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...
You must first be a registered member to view any code.
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.

You must first be a registered member to view any code.
In PHP it would look like this.
You must first be a registered member to view any code.
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.

You must first be a registered member to view any code.
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:

You must first be a registered member to view any code.
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.
__________________
Earnersforum.com - Learn how to make money online! New Look!

Ken Iovino / vBHackers.com
vBSEO 3.1 GOLD Released vB Blogs Compatible | Non-Encrypted | Branding Removal Option | Sitemaps 2.1 | Language Packs

Crawlability Network: vBulletin SEO | vBulletin Hackers




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 03-17-2006, 07:36 AM   #2
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Very nice tut =)




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-17-2006, 07:56 AM   #3
Coder
Junior's Avatar
Join Date: Nov 2004
Real Name: jr
Location: U.S.A
Junior is on a distinguished road

Default

idd very nice




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-17-2006, 01:45 PM   #4
Coder
Idan's Avatar
Join Date: Feb 2005
Real Name: Idan
Location: Israel
Idan is on a distinguished road

Default

yep, very nice tut indeed. :]




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-17-2006, 08:31 PM   #5
Coder
Maxx's Avatar
Join Date: Sep 2004
Location: U.K
Maxx is on a distinguished road

Default

well done on tut ;)




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-20-2006, 07:35 AM   #6
Junior Member
Join Date: Feb 2006
scorpio is on a distinguished road

Default

many thanks for ut tutorial....




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-15-2006, 12:25 PM   #7
tgreer
Guest

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?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-15-2006, 12:29 PM   #8
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

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.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-15-2006, 12:43 PM   #9
tgreer
Guest

Default

So, in terms of this tutorial...

THIS:

You must first be a registered member to view any code.
needs to come BEFORE, THIS:

You must first be a registered member to view any code.
??

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?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-16-2006, 06:45 PM   #10
Ken Iovino
Founder
Ken Iovino's Avatar
Join Date: Mar 2004
Real Name: Ken Iovino
Location: Miami, Florida
Ken Iovino is on a distinguished road

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
__________________
Earnersforum.com - Learn how to make money online! New Look!

Ken Iovino / vBHackers.com
vBSEO 3.1 GOLD Released vB Blogs Compatible | Non-Encrypted | Branding Removal Option | Sitemaps 2.1 | Language Packs

Crawlability Network: vBulletin SEO | vBulletin Hackers




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



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

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 Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Install system updated Ken Iovino Announcements 7 11-17-2006 02:59 PM
Not Your Normal Marquee System Sezmar vBulletin 3.5 / 3.6 Hack Releases 22 09-19-2006 08:41 AM
[REQUEST] Rating System (Possibly by TouchingVirus or ShavedApe?) figure004 vBulletin Modification Requests 4 05-22-2005 04:14 PM


All times are GMT -3. The time now is 11:34 AM.


SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc. (Patent Pending)