Jump to content

Manual:Hooks/RejectParserCacheValue

From mediawiki.org
RejectParserCacheValue
Available from version 1.26.0 (Gerrit change I660679a48c)
Return false to reject an otherwise usable cached value from the Parser cache.
Define function:
public static function onRejectParserCacheValue( $parserOutput, $wikiPage, $parserOptions ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"RejectParserCacheValue": "MediaWiki\\Extension\\MyExtension\\Hooks::onRejectParserCacheValue"
	}
}
Called from: File(s): Parser/ParserCache.php
Function(s): get
Interface: RejectParserCacheValueHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:RejectParserCacheValue extensions.

Summary

[edit]
Warning Warning: Misuse of this hook can effectively disable the parser cache, with serious consequences for high-traffic installations. Use with extreme care.

This hook allows extensions to reject an otherwise-successful parser cache lookup. The intent is to allow extensions to manage the eviction of archaic HTML output from the cache.

Return true or no return value to continue, or false to reject an otherwise usable cached value from the Parser cache.

Use Case

[edit]

See patch 587264 in gerrit for an example of the use of this hook in WMF production to mitigate an issue which caused parser cache corruption. Searching for RejectParserCache in the mediawiki-config repository using git log -SRejectParserCache or equivalent will list other examples of use in WMF production. See T296425 for equivalent code to manage stored content stored in RESTBase.

Record Parsoid version in extension data to allow rollback if necessary (942029) was added in core to allow parser cache rejection based on a specific Parsoid version. The extension data is set to the output of Parsoid::version() which looks like "0.24.0.0-alpha2" -- that is, alpha is spelled out, and it has an additional .0 for "patch version". You can also see this string at the bottom of the limit report on any page parsed with Parsoid, eg:

<!-- Saved in parser cache with key enwiki:parsoid-pcache:2989630:|#|:idhash:useParsoid=1 and timestamp 20260511042610 and revision id 1351531145. Rendering was triggered because: MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getParserOutput
 -->
<!-- Parsoid 0.24.0.0-alpha2 -->

In the worse case this can be searched for in the raw HTML, instead of the extension data.

Parameters

[edit]
  • $parserOutput: ParserOutput object
  • $wikiPage: WikiPage object
  • $parserOptions: ParserOptions object