Log in

View Full Version : [how-to] Cache some table


Milad
02-03-2006, 12:33 AM
How to cache a table and insert it into datastore table or in datastor file?

like forumcache

thanks in advance

Nullifi3d
02-03-2006, 01:22 AM
Are you asking how to store a table's fields in a php variable? as $vbulletin->userinfo stores the user table?

Milad
02-03-2006, 01:27 AM
No
Something like $vbulletin->cacheforum

Nullifi3d
02-03-2006, 01:34 AM
Sorry, I'm not quite sure what you're referring to. Maybe someone else will know.

Milad
02-03-2006, 01:37 AM
$vbulletin->forumcache exactly

thank you

Nullifi3d
02-03-2006, 01:48 AM
What do you want to cache? A mysql table (as you said in your first post) or a forum?

Milad
02-03-2006, 01:50 AM
Now I'm working on a hack for vBulletin and I want to cache my categories to deal easily with them.

Of course categories are in new table

Nullifi3d
02-03-2006, 02:06 AM
In that case you use php code like this:
$tableinfo = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "tablename WHERE userid = " . $_REQUEST['userid']);
You would change tablename to the name of the mysql table that is storing you hack's data. the * tells mysql to store (cache) each row in that table in the variable $tableinfo (which you can name this whatever you want). This way if you have a row/field named username that stores the usernames for everyone the username for $_REQUEST['userid'] would be called with $tablename['username'];
If you need anymore help let me know.

Milad
02-03-2006, 02:11 AM
Dear
This isn't caching, caching makes you avoid this query, I think.

thank you

Nullifi3d
02-03-2006, 02:19 AM
Ohh, well I don't know then, sorry.

Adrian Schneider
02-03-2006, 02:27 AM
Query it, create a serialized version of the resultset, then insert that into a new datastore column.

Place the colum name in the $specialtemplates array in your script (and unserialize) and you won't have to query for it every time.

Milad
02-03-2006, 02:41 AM
THank you
This is exactly what I want
But can you gice a php example?

Adrian Schneider
02-03-2006, 03:17 AM
wrote this real quick

// Preparing
$eggnog = $db->query_read("
SELECT *
FROM stuff
ORDER BY stuffName ASC
");

$allNogs = array();
while ($nog = $db->fetch_array($eggnog))
{
$allNogs[] = $nog;
}

$serialized = serialize($allNogs);

$db->query_write("
UPDATE " . TABLE_PREFIX . "datastore
SET data = '" . $db->escape_string($serialized) . "'
WHERE title = 'nog'
");

// Usage

$specialtemplates = array(
'nog'
);

require_once('./global.php');

//$vbulletin->nog now contains serialized array

$vbulletin->nog = unserialize($vbulletin->nog);

Milad
02-03-2006, 06:10 AM
Thank you very much.

$db->query_write("
UPDATE " . TABLE_PREFIX . "datastore
SET data = '" . $db->escape_string($serialized) . "'
WHERE title = 'nog'
");

I think we can use build_datastore instead of this query