vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Cache System Explanation (datastore) (https://vborg.vbsupport.ru/showthread.php?t=110628)

seko3 06-06-2008 06:17 PM

Quote:

Originally Posted by briansol (Post 1542079)
With a couple tweaks (probably because this is 2 years old...), i've successfully got my first datastore plugin working :)

Thanks for the write up Ken. Never experienced with the datastore much.

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.

RobDog888 06-06-2008 08:10 PM

Quote:

Originally Posted by briansol (Post 1542079)
With a couple tweaks (probably because this is 2 years old...), i've successfully got my first datastore plugin working :)

Thanks for the write up Ken. Never experienced with the datastore much.

What was different from the posted solutions?

briansol 06-06-2008 08:15 PM

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);

?>

Again, you can skip truncating and building the table... just run the big query here as the $query = part to get your array/data.


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:

Product : SKM - Active threads from past 24 hours
SKM Active Threads - Cache output templates cache_templates
SKM Active Threads - Cache Special Templates (datastore row) init_startup
SKM Active Threads - Parse and Print forumhome_complete
SKM Active Threads - Template Group template_groups
a) cache_templates hook : contains the simple caching of my custom template which prints 1 row of data (ie, <tr><td>1</td><td>2</td></tr> ) similar to the 'threadbits' template

it contains a simple line:
Code:

$globaltemplates[] = 'skm_activethreads24_forumhome';
b) init_startup hook : special templates is probably a mis-nomer at this point, as i'm NOT using the special templates array merge style.
This file pulls the datastore row into memory:
Code:

$datastore_fetch[] = "'skm_active_cache'";
note the quotes are important. This name should match what you ran in your cron under the build_datastore() function.

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')."\";");
}

d) the template will look for the $output array to print, ala:
Code:

<a href="showthread.php?t=$output[threadid]&amp;goto=newpost">
e) the template group is not required... just makes things easier to group when you have a lot of templates.


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.

gabrielt 01-02-2009 08:21 PM

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.

Jafo232 02-11-2009 03:20 PM

Quote:

Originally Posted by gabrielt (Post 1699658)

And I also needed to add a plugin for the init_startup hook, adding:

$datastore_fetch[]="'name'";

This should really be added to the first post. Took forever to figure this out. :)

bananalive 04-21-2009 05:42 PM

Is there a datastore per user?

mokujin 04-21-2009 09:23 PM

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";
        }
}


rob01 04-21-2009 10:59 PM

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?

solita_ugc 05-11-2009 05:22 AM

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

IdanB 05-22-2009 09:58 AM

Quote:

Originally Posted by gabrielt (Post 1699658)
And I also needed to add a plugin for the init_startup hook, adding:

$datastore_fetch[]="'name'";

Thank you for this, was pulling my hair out my head trying to get this to work.
That's what i was missing :)


All times are GMT. The time now is 04:47 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01994 seconds
  • Memory Usage 1,755KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete