PDA

View Full Version : Any way to turn off post cache when a particular bb code is used?


BirdOPrey5
01-12-2011, 11:58 PM
I have a BB Code that I modify the exact size of based off a custom user profile field.

I do this by using a hook on bbcode_parse_start, scanning the code for this bb code, and if found setting a custom height.

However while this seemed to work I notice now that the size is usually set by the first person to view it and I guess it's cached. Subsequent viewers don't see it at their specified height but that of whomever viewed it first's height.

This isn't an often used bb code so i figured disabling the post cache if this bb code was used wouldn't be a big deal.

However I'm not seeing how to do this... the code in class_bbcode.php to test if it is cachable is:
if ($this->options['cachable'])

So I tried just setting $this->options['cachable'] = false, but it doesn't seem to do anything at all.

Would there be some other way of turning off the post cache for a specific post?

kh99
01-13-2011, 09:59 AM
I'm not completely sure if I know what's going on in the code, or if I get what you're asking, but I think there's different kinds of caching going on. One is to cache results during the processing of a page so that work isn't repeated, like parsing the same signatures over and over in the a thread. Then there's the post cache that survives between user requests. So I think that 'cachable' field in class_bbcode might be for caching signatures during one page request but not between (different users') requests. (I know this doesn't really help you solve your problem).

BirdOPrey5
01-13-2011, 11:01 AM
Basically I have a BB Code... in the replacement code there used to be a part that said height="400" in an HTML tag.

But some users with high resolution screens asked for it to be taller than 400 pixels... So I made a custom user profile field where each user can specify the height they want for this particular BB Code.

In the BB Code replacement I changed it from height="400" to height="xxx" (for example) and then on the hook bbcode_parse_start I do a str_replace for "xxx" and swap in the value set by the user in their profile field. For the most part this works except sometimes it gets cached at a different user's value.

In class_bbcode.php there are the following lines around line 440...



// save the cached post
if ($this->options['cachable'])
{
$this->cached['text'] = $text;
$this->cached['has_images'] = $has_img_tag;
}

// do [img] tags if the item contains images
if(($do_bbcode OR $do_imgcode) AND $has_img_tag)
{
$text = $this->handle_bbcode_img($text, $do_imgcode, $has_img_tag);
}

($hook = vBulletinHook::fetch_hook('bbcode_parse_complete') ) ? eval($hook) : false;

return $text;


I *think* what I have to do is to make this condition false when a specific BB Code is present in $text. (Which is already converted to HTML at this point).

My main question is how can I change the value of $this->options['cachable'] because simply setting it equal to zero or false doesn't appear to have any affect.

Unless what you're telling me it might be working but it's cached somewhere else...

kh99
01-13-2011, 01:55 PM
Unless what you're telling me it might be working but it's cached somewhere else...

Yeah, I guess I was saying that I think the cachable variable in class_bbcode isn't what controls caching of posts across different user requests (like you're describing). But in retrospect I probably shouldn't have replied at all unless I had a better answer than that. :)

BirdOPrey5
01-13-2011, 01:58 PM
Yeah, I guess I was saying that I think the cachable variable in class_bbcode isn't what controls caching of posts across different user requests (like you're describing). But in retrospect I probably shouldn't have replied at all unless I had a better answer than that. :)

Your replies are ALWAYS welcome. :up:

dartho
02-13-2011, 10:58 AM
How did you go here BirdOfPrey5 - I'm looking for something similar ...

BirdOPrey5
02-13-2011, 12:29 PM
I never did figure it out really... instead of doing the replacements on bbcode_parse_start and bbcode_parse_complete_precache I instead did them on postbit_display_complete, newpost_preview, and newreply_form_reviewbit and I didn't run into the cache issues with these hooks.

The down side is that I needed 3 plugins instead of 2 and it won't work if I ever needed to use the bb code outside a post (say in a social group or signature) but I won't so it's not a big deal- otherwise I'd need even more plugins for those locations.