Make ParserCache use CachedBagOStuff

Bug: T269593
Change-Id: I21e6e39eccad22b781252b142c1e5b079c1ee0b4
This commit is contained in:
Petr Pchelko 2020-12-07 09:35:18 -06:00
parent 66e41027b1
commit 66cc685b45
3 changed files with 15 additions and 6 deletions

View file

@ -142,6 +142,13 @@ class ParserCache {
LoggerInterface $logger, LoggerInterface $logger,
$useJson = false $useJson = false
) { ) {
if ( !$cache instanceof EmptyBagOStuff && !$cache instanceof CachedBagOStuff ) {
$cache = new CachedBagOStuff( $cache, [
// Each ParserCache entry uses 2 keys, one for metadata and one for parser output.
// So, cache at most 4 different parser outputs in memory. The number was chosen ad hoc.
'maxKeys' => 8
] );
}
$this->name = $name; $this->name = $name;
$this->cache = $cache; $this->cache = $cache;
$this->cacheEpoch = $cacheEpoch; $this->cacheEpoch = $cacheEpoch;

View file

@ -576,8 +576,7 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
* @param string $data * @param string $data
*/ */
public function testCorruptData( bool $json, string $data ) { public function testCorruptData( bool $json, string $data ) {
$bag = new HashBagOStuff(); $cache = $this->createParserCache( null, new HashBagOStuff() );
$cache = $this->createParserCache( null, $bag );
$cache->setJsonSupport( $json, $json ); $cache->setJsonSupport( $json, $json );
$parserOutput = new ParserOutput( 'TEST_TEXT' ); $parserOutput = new ParserOutput( 'TEST_TEXT' );
@ -590,7 +589,7 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
$parserOutput->getUsedOptions() $parserOutput->getUsedOptions()
); );
$bag->set( $outputKey, $data ); $cache->getCacheStorage()->set( $outputKey, $data );
// just make sure we don't crash and burn // just make sure we don't crash and burn
$this->assertFalse( $cache->get( $this->page, $options1 ) ); $this->assertFalse( $cache->get( $this->page, $options1 ) );
@ -607,8 +606,7 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
*/ */
public function testCorruptMetadata() { public function testCorruptMetadata() {
$this->hideDeprecated( 'ParserCache::getKey' ); $this->hideDeprecated( 'ParserCache::getKey' );
$bag = new HashBagOStuff(); $cache = $this->createParserCache( null, new HashBagOStuff() );
$cache = $this->createParserCache( null, $bag );
$parserOutput = new ParserOutput( 'TEST_TEXT' ); $parserOutput = new ParserOutput( 'TEST_TEXT' );
$options1 = ParserOptions::newCanonical( 'canonical' ); $options1 = ParserOptions::newCanonical( 'canonical' );
@ -618,7 +616,7 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
$this->page $this->page
); );
$bag->set( $optionsKey, 'bad data' ); $cache->getCacheStorage()->set( $optionsKey, 'bad data' );
// just make sure we don't crash and burn // just make sure we don't crash and burn
$this->assertNull( $cache->getMetadata( $this->page ) ); $this->assertNull( $cache->getMetadata( $this->page ) );

View file

@ -24,4 +24,8 @@ class ParserCacheFactoryTest extends MediaWikiUnitTestCase {
// $name // $name
return 1; return 1;
} }
protected function getIgnoredParamNames() {
return [ 'cacheBackend', 'hookContainer' ];
}
} }