MediaWiki  master
ParserCacheFactory.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Parser;
23 
24 use BagOStuff;
30 use ParserCache;
31 use Psr\Log\LoggerInterface;
32 use TitleFactory;
33 use WANObjectCache;
34 
41 
43  public const DEFAULT_NAME = 'pcache';
44 
47 
50 
52  private $hookContainer;
53 
55  private $jsonCodec;
56 
58  private $stats;
59 
61  private $logger;
62 
64  private $titleFactory;
65 
68 
70  private $parserCaches = [];
71 
73  private $revisionOutputCaches = [];
74 
76  private $options;
77 
81  public const CONSTRUCTOR_OPTIONS = [
82  'ParserCacheUseJson', // Temporary feature flag, remove before 1.36 is released.
83  'CacheEpoch',
84  'OldRevisionParserCacheExpireTime',
85  ];
86 
98  public function __construct(
101  HookContainer $hookContainer,
102  JsonCodec $jsonCodec,
104  LoggerInterface $logger,
105  ServiceOptions $options,
107  WikiPageFactory $wikiPageFactory
108  ) {
109  $this->parserCacheBackend = $parserCacheBackend;
110  $this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
111  $this->hookContainer = $hookContainer;
112  $this->jsonCodec = $jsonCodec;
113  $this->stats = $stats;
114  $this->logger = $logger;
115 
116  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
117  $this->options = $options;
118  $this->titleFactory = $titleFactory;
119  $this->wikiPageFactory = $wikiPageFactory;
120  }
121 
127  public function getParserCache( string $name ): ParserCache {
128  if ( !isset( $this->parserCaches[$name] ) ) {
129  $this->logger->debug( "Creating ParserCache instance for {$name}" );
130  $cache = new ParserCache(
131  $name,
132  $this->parserCacheBackend,
133  $this->options->get( 'CacheEpoch' ),
134  $this->hookContainer,
135  $this->jsonCodec,
136  $this->stats,
137  $this->logger,
138  $this->titleFactory,
139  $this->wikiPageFactory,
140  $this->options->get( 'ParserCacheUseJson' )
141  );
142 
143  $this->parserCaches[$name] = $cache;
144  }
145  return $this->parserCaches[$name];
146  }
147 
153  public function getRevisionOutputCache( string $name ): RevisionOutputCache {
154  if ( !isset( $this->revisionOutputCaches[$name] ) ) {
155  $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
157  $name,
158  $this->revisionOutputCacheBackend,
159  $this->options->get( 'OldRevisionParserCacheExpireTime' ),
160  $this->options->get( 'CacheEpoch' ),
161  $this->jsonCodec,
162  $this->stats,
163  $this->logger
164  );
165 
166  $this->revisionOutputCaches[$name] = $cache;
167  }
168  return $this->revisionOutputCaches[$name];
169  }
170 }
Parser\ParserCacheFactory\$titleFactory
TitleFactory $titleFactory
Definition: ParserCacheFactory.php:64
Parser\ParserCacheFactory\$hookContainer
HookContainer $hookContainer
Definition: ParserCacheFactory.php:52
MediaWiki\Parser
Definition: ParserCacheFactory.php:22
Parser\ParserCacheFactory\$revisionOutputCacheBackend
WANObjectCache $revisionOutputCacheBackend
Definition: ParserCacheFactory.php:49
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:86
Parser\ParserCacheFactory\$logger
LoggerInterface $logger
Definition: ParserCacheFactory.php:61
Parser\ParserCacheFactory
Definition: ParserCacheFactory.php:40
Parser\ParserCacheFactory\$wikiPageFactory
WikiPageFactory $wikiPageFactory
Definition: ParserCacheFactory.php:67
Parser\ParserCacheFactory\$parserCacheBackend
BagOStuff $parserCacheBackend
Definition: ParserCacheFactory.php:42
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:27
Page\WikiPageFactory
Definition: WikiPageFactory.php:20
Parser\ParserCacheFactory\$revisionOutputCaches
RevisionOutputCache[] $revisionOutputCaches
Definition: ParserCacheFactory.php:73
Parser\ParserCacheFactory\$parserCaches
ParserCache[] $parserCaches
Definition: ParserCacheFactory.php:70
Parser\ParserCacheFactory\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition: ParserCacheFactory.php:81
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:137
Parser\ParserCacheFactory\$stats
IBufferingStatsdDataFactory $stats
Definition: ParserCacheFactory.php:58
Parser\ParserCacheFactory\getRevisionOutputCache
getRevisionOutputCache(string $name)
Get a RevisionOutputCache instance by $name.
Definition: ParserCacheFactory.php:153
IBufferingStatsdDataFactory
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.
Definition: IBufferingStatsdDataFactory.php:13
Parser\RevisionOutputCache
Cache for ParserOutput objects.
Definition: RevisionOutputCache.php:44
$cache
$cache
Definition: mcc.php:33
Parser\ParserCacheFactory\getParserCache
getParserCache(string $name)
Get a ParserCache instance by $name.
Definition: ParserCacheFactory.php:127
TitleFactory
Creates Title objects.
Definition: TitleFactory.php:35
ParserCache
Cache for ParserOutput objects corresponding to the latest page revisions.
Definition: ParserCache.php:63
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
MediaWiki\Json\JsonCodec
Definition: JsonCodec.php:36
Parser\ParserCacheFactory\$options
ServiceOptions $options
Definition: ParserCacheFactory.php:76
Parser\ParserCacheFactory\$jsonCodec
JsonCodec $jsonCodec
Definition: ParserCacheFactory.php:55
Parser\ParserCacheFactory\__construct
__construct(BagOStuff $parserCacheBackend, WANObjectCache $revisionOutputCacheBackend, HookContainer $hookContainer, JsonCodec $jsonCodec, IBufferingStatsdDataFactory $stats, LoggerInterface $logger, ServiceOptions $options, TitleFactory $titleFactory, WikiPageFactory $wikiPageFactory)
Definition: ParserCacheFactory.php:98