* @ingroup Parser
*/
// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
-class Preprocessor_Hash implements Preprocessor {
+class Preprocessor_Hash extends Preprocessor {
// @codingStandardsIgnoreEnd
/**
*/
public $parser;
- const CACHE_VERSION = 1;
+ const CACHE_PREFIX = 'preprocess-hash';
public function __construct( $parser ) {
$this->parser = $parser;
return $node;
}
+
/**
* Preprocess some wikitext and return the document tree.
* This is the ghost of Parser::replace_variables().
* @return PPNode_Hash_Tree
*/
public function preprocessToObj( $text, $flags = 0 ) {
- // Check cache.
- global $wgMemc, $wgPreprocessorCacheThreshold;
-
- $cacheable = $wgPreprocessorCacheThreshold !== false
- && strlen( $text ) > $wgPreprocessorCacheThreshold;
-
- if ( $cacheable ) {
- $cacheKey = wfMemcKey( 'preprocess-hash', md5( $text ), $flags );
- $cacheValue = $wgMemc->get( $cacheKey );
- if ( $cacheValue ) {
- $version = substr( $cacheValue, 0, 8 );
- if ( intval( $version ) == self::CACHE_VERSION ) {
- $hash = unserialize( substr( $cacheValue, 8 ) );
- // From the cache
- wfDebugLog( "Preprocessor",
- "Loaded preprocessor hash from memcached (key $cacheKey)" );
- return $hash;
- }
- }
+ $tree = $this->cacheGetTree( $text, $flags );
+ if ( $tree !== false ) {
+ return unserialize( $tree );
}
$rules = array(
$lastNode = $node;
}
if ( !$node ) {
- if ( $cacheable ) {
- }
+ // if ( $cacheable ) { ... }
throw new MWException( __METHOD__ . ': eqpos not found' );
}
if ( $node->name !== 'equals' ) {
- if ( $cacheable ) {
- }
+ // if ( $cacheable ) { ... }
throw new MWException( __METHOD__ . ': eqpos is not equals' );
}
$equalsNode = $node;
$rootNode->lastChild = $stack->rootAccum->lastNode;
// Cache
- if ( $cacheable ) {
- $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . serialize( $rootNode );
-
- // T111289: Cache values should not exceed 1 Mb, but they do.
- if ( strlen( $cacheValue ) <= 1e6 ) {
- $wgMemc->set( $cacheKey, $cacheValue, 86400 );
- wfDebugLog( "Preprocessor", "Saved preprocessor Hash to memcached (key $cacheKey)" );
- }
- }
+ $this->cacheSetTree( $text, $flags, serialize( $rootNode ) );
return $rootNode;
}