wiki.techinc.nl/includes/page/PageStoreFactory.php
daniel 3b6345ca16 PageStore: Use LinkCache
This makes the data stored by LinkCache compatible with PageStoreRecord,
so we can use LinkCache inside PageStore.

This causes PageStore to make use of local caching as well as WANObjectCache.

Note that getPageById() does not yet benefit from cache, but does
populate the cache.

Bug: T278940
Change-Id: Icc27a0d9299a3e4ce45521daef87ad06ec06f064
2021-09-01 08:24:34 +00:00

84 lines
1.8 KiB
PHP

<?php
namespace MediaWiki\Page;
use LinkCache;
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\DAO\WikiAwareEntity;
use NamespaceInfo;
use TitleParser;
use Wikimedia\Rdbms\ILBFactory;
/**
* @since 1.36
*/
class PageStoreFactory {
/**
* @internal for use by service wiring
*/
public const CONSTRUCTOR_OPTIONS = PageStore::CONSTRUCTOR_OPTIONS;
/** @var ServiceOptions */
private $options;
/** @var ILBFactory */
private $dbLoadBalancerFactory;
/** @var NamespaceInfo */
private $namespaceInfo;
/** @var TitleParser */
private $titleParser;
/** @var LinkCache */
private $linkCache;
/** @var StatsdDataFactoryInterface */
private $stats;
/**
* @param ServiceOptions $options
* @param ILBFactory $dbLoadBalancerFactory
* @param NamespaceInfo $namespaceInfo
* @param TitleParser $titleParser
* @param LinkCache $linkCache
* @param StatsdDataFactoryInterface $stats
*/
public function __construct(
ServiceOptions $options,
ILBFactory $dbLoadBalancerFactory,
NamespaceInfo $namespaceInfo,
TitleParser $titleParser,
LinkCache $linkCache,
StatsdDataFactoryInterface $stats
) {
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->options = $options;
$this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
$this->namespaceInfo = $namespaceInfo;
$this->titleParser = $titleParser;
$this->linkCache = $linkCache;
$this->stats = $stats;
}
/**
* @param string|false $wikiId
*
* @return PageStore
*/
public function getPageStore( $wikiId = WikiAwareEntity::LOCAL ): PageStore {
return new PageStore(
$this->options,
$this->dbLoadBalancerFactory->getMainLB( $wikiId ),
$this->namespaceInfo,
$this->titleParser,
$wikiId !== WikiAwareEntity::LOCAL ? null : $this->linkCache,
$this->stats,
$wikiId
);
}
}