Pages that are fast to render can be omitted from the parser cache to preserve disk space and cache write operations. The threshold is configurable per namespace, so the tradeoff can be evaluated based on different access patterns. For example, pages that are accessed rarely, like file description pages on commons, may have a high threshold configured, while pages that are read frequently, like wikipedia articles, may be configured to be always cached, using a 0 threshold. Filtering is based on a time profile recorded in the ParserOutput. A generic mechanism for capturing the timing profile is implemented in the ContentHandler base class. Subclasses may implement a more rigorous capture mechanism. Bug: T346765 Change-Id: I38a6f3ef064f98f3ad6a7c60856b0248a94fe9ac
68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
use MediaWiki\Json\JsonCodec;
|
|
use MediaWiki\MainConfigNames;
|
|
use MediaWiki\MainConfigSchema;
|
|
use MediaWiki\Page\WikiPageFactory;
|
|
use MediaWiki\Parser\ParserCacheFactory;
|
|
use MediaWiki\Parser\RevisionOutputCache;
|
|
use MediaWiki\Title\TitleFactory;
|
|
use Psr\Log\NullLogger;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Parser\ParserCacheFactory
|
|
*/
|
|
class ParserCacheFactoryTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @return ParserCacheFactory
|
|
*/
|
|
private function newParserCacheFactory() {
|
|
$options = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
|
|
MainConfigNames::CacheEpoch => '20200202112233',
|
|
MainConfigNames::OldRevisionParserCacheExpireTime => 60,
|
|
MainConfigNames::ParserCacheFilterConfig
|
|
=> MainConfigSchema::getDefaultValue( MainConfigNames::ParserCacheFilterConfig ),
|
|
] );
|
|
|
|
return new ParserCacheFactory(
|
|
new HashBagOStuff(),
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
|
|
$this->createHookContainer(),
|
|
new JsonCodec(),
|
|
new NullStatsdDataFactory(),
|
|
new NullLogger(),
|
|
$options,
|
|
$this->createNoOpMock( TitleFactory::class ),
|
|
$this->createNoOpMock( WikiPageFactory::class )
|
|
);
|
|
}
|
|
|
|
public function testGetParserCache() {
|
|
$factory = $this->newParserCacheFactory();
|
|
|
|
$a = $factory->getParserCache( 'test' );
|
|
$this->assertInstanceOf( ParserCache::class, $a );
|
|
|
|
$b = $factory->getParserCache( 'test' );
|
|
$this->assertSame( $a, $b );
|
|
|
|
$c = $factory->getParserCache( 'xyzzy' );
|
|
$this->assertNotSame( $a, $c );
|
|
}
|
|
|
|
public function testGetRevisionOutputCache() {
|
|
$factory = $this->newParserCacheFactory();
|
|
|
|
$a = $factory->getRevisionOutputCache( 'test' );
|
|
$this->assertInstanceOf( RevisionOutputCache::class, $a );
|
|
|
|
$b = $factory->getRevisionOutputCache( 'test' );
|
|
$this->assertSame( $a, $b );
|
|
|
|
$c = $factory->getRevisionOutputCache( 'xyzzy' );
|
|
$this->assertNotSame( $a, $c );
|
|
}
|
|
|
|
}
|