Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2009, 10:22 AM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Custom items in VB datastore

Without getting into the whys and wherefores I have coded a page that displays a lot of data that is pulled from the database, this works perfectly and all is good.

However, there is no need for this data to be re-queried on every page view so the obvious solution is the cache the data, when needed pull it from the cache and periodically purge and refresh the cache.

It seems like a good idea to reuse as much of the existing datastore system that already exists in vBulletin. I can store into the cache using:

Code:
build_datastore('mycustomdata', serialize($mycustomdata), 1);
However, how do I retrieve from the store?

I did consider putting it into something like $vbulletin->options but this would mean that the data would be loaded in on all pages which is unnecessary and would waste resources.

--------------- Added [DATE]1254311069[/DATE] at [TIME]1254311069[/TIME] ---------------

Problem Solved

To do this you need to give your custom datastore a name, and then pass this name to the $specialtemplates array.

Code speaks a thousand words, so...

Code:
<?php
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'testvbcache');

$phrasegroups = array();
$specialtemplates = array('mycustomdatastoretemplate');
$globaltemplates = array();
$actiontemplates = array();

require_once('./global.php');

if (isset($vbulletin->mycustomdatastoretemplate))
{
	//The custom datastore item is available so just echo out the current
	//datastore value.
	echo 'RETRIEVED: ' . $vbulletin->mycustomdatastoretemplate['arraykey'];
}
else
{
	//The custom datastore item is not available so create it and add to
	//the datastore
	$mycustomdata = array();
	$mycustomdata['arraykey'] = 'This is the value of array key';
	build_datastore('mycustomdatastoretemplate', serialize($mycustomdata), 1);
	
	echo 'ADDED: ' . $mycustomdata['arraykey'];
}
?>
The part in bold red is the important bit, without this the VB backend will not load in your custom datastore values.

The first time this script is run it will output:

Code:
ADDED: This is the value of array key
The second time (and all subsequent calls) it will output

Code:
RETRIEVED: This is the value of array key
Reply With Quote
  #2  
Old 09-30-2009, 02:38 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

One of these days I will look into all this datastoring cuz I can think of a couple places on my site where it would be very useful to use. Thanks for taking the time out to post this because I'm sure it will help someone (like me!) when they are looking into this same thing.
Reply With Quote
  #3  
Old 09-30-2009, 04:23 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
define('NO_REGISTER_GLOBALS'1); 
Unneeded old code - get rid of it
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 06:49 PM.


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.03973 seconds
  • Memory Usage 2,186KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete