I wrote a parser tag that displays some user options that are set in Special:Preference. It gets embedded in an article like this:
<mystuff/>
However, when users change their options, my parser tag appears still displays old, cached data. I have tried everything I can think of to stop this caching:
static function myHookFunction($input, $args, $parser) { $parser->disableCache(); global $wgEnableParserCache, $wgCachePages, $wgParser; $wgParser->disableCache(); $wgEnableParserCache = false; $wgCachePages = false; ... }
But all of this has no effect. The only way to get the new data to appear is to edit the page or use ?action=purge.
Coincidentally, I have another extension that displays the same data (not using a parser tag, but an ordinary callback via $wgHooks['OutputPageBeforeHTML']), and the data is always up to date.
Both extensions use User::newFromName($username) to obtain User objects, and $user->getOption() to get the values. But I don't think the User class is causing this. When I make code changes to my parser tag, I don't even see the results of the changes until I edit the page or use ?action=purge.
We are not running any other external caches at the PHP or web level.
What am I missing?
Thanks, DanB
On Wed, Aug 3, 2011 at 5:14 AM, Daniel Barrett danb@vistaprint.com wrote:
I wrote a parser tag that displays some user options that are set in Special:Preference. It gets embedded in an article like this:
<mystuff/>
However, when users change their options, my parser tag appears still displays old, cached data. I have tried everything I can think of to stop this caching:
Here's the hook you want:
'PageRenderingHash': alter the parser cache option hash key A parser extension which depends on user options should install this hook and append its values to the key. $hash: reference to a hash key string which can be modified
If working for the latest MW versions only, you can also stick a flag in the parser output to indicate whether the feature was used, so it doesn't need to be included in the hash when not set. I forget offhand exactly how to do that, but you can look around at some of the parser internals if you dare. ;)
-- brion
Here's the hook you want: 'PageRenderingHash'...
Thanks very much, Brion. Do you have an example of using this hook when you want multiple user options not to be cached? The examples on http://www.mediawiki.org/wiki/Category:PageRenderingHash_extensions are really minimal and involve cryptic things like "!" characters when the docs say to use a "hash", e.g.,
function ImageFilterHash( $hash ) ... $hash .= '!' . ( $wgUser->getOption( 'displayfiltered' ) ? '1' : '' );
Thanks, DanB
Thanks very much, Brion. Do you have an example of using this hook when you want multiple user options not to be cached...
Oh wait, I get it, now that I've looked at User.php. You mean "hash" as in "hashed value". I assumed "hash" as in "hashtable/associative array".
DanB
Daniel Barrett wrote:
I wrote a parser tag that displays some user options that are set in Special:Preference. It gets embedded in an article like this:
<mystuff/>
However, when users change their options, my parser tag appears still displays old, cached data. I have tried everything I can think of to stop this caching:
static function myHookFunction($input, $args, $parser) { $parser->disableCache(); global $wgEnableParserCache, $wgCachePages, $wgParser; $wgParser->disableCache(); $wgEnableParserCache = false; $wgCachePages = false; ... }
$parser->disableCache(); should have worked. Which MediaWiki version are you using? Were you using the file cache?
mediawiki-l@lists.wikimedia.org