MediaWiki  master
ParserCacheFactory.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Parser;
23 
24 use BagOStuff;
31 use ParserCache;
32 use Psr\Log\LoggerInterface;
33 use TitleFactory;
34 use WANObjectCache;
35 
42 
44  public const DEFAULT_NAME = 'pcache';
45 
48 
51 
53  private $hookContainer;
54 
56  private $jsonCodec;
57 
59  private $stats;
60 
62  private $logger;
63 
65  private $titleFactory;
66 
69 
71  private $parserCaches = [];
72 
74  private $revisionOutputCaches = [];
75 
77  private $options;
78 
82  public const CONSTRUCTOR_OPTIONS = [
83  MainConfigNames::ParserCacheUseJson, // Temporary feature flag, remove before 1.36 is released.
86  ];
87 
99  public function __construct(
102  HookContainer $hookContainer,
103  JsonCodec $jsonCodec,
105  LoggerInterface $logger,
106  ServiceOptions $options,
108  WikiPageFactory $wikiPageFactory
109  ) {
110  $this->parserCacheBackend = $parserCacheBackend;
111  $this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
112  $this->hookContainer = $hookContainer;
113  $this->jsonCodec = $jsonCodec;
114  $this->stats = $stats;
115  $this->logger = $logger;
116 
117  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
118  $this->options = $options;
119  $this->titleFactory = $titleFactory;
120  $this->wikiPageFactory = $wikiPageFactory;
121  }
122 
128  public function getParserCache( string $name ): ParserCache {
129  if ( !isset( $this->parserCaches[$name] ) ) {
130  $this->logger->debug( "Creating ParserCache instance for {$name}" );
131  $cache = new ParserCache(
132  $name,
133  $this->parserCacheBackend,
134  $this->options->get( MainConfigNames::CacheEpoch ),
135  $this->hookContainer,
136  $this->jsonCodec,
137  $this->stats,
138  $this->logger,
139  $this->titleFactory,
140  $this->wikiPageFactory,
141  $this->options->get( MainConfigNames::ParserCacheUseJson )
142  );
143 
144  $this->parserCaches[$name] = $cache;
145  }
146  return $this->parserCaches[$name];
147  }
148 
154  public function getRevisionOutputCache( string $name ): RevisionOutputCache {
155  if ( !isset( $this->revisionOutputCaches[$name] ) ) {
156  $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
158  $name,
159  $this->revisionOutputCacheBackend,
161  $this->options->get( MainConfigNames::CacheEpoch ),
162  $this->jsonCodec,
163  $this->stats,
164  $this->logger
165  );
166 
167  $this->revisionOutputCaches[$name] = $cache;
168  }
169  return $this->revisionOutputCaches[$name];
170  }
171 }
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition: WebStart.php:82
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:87
A class for passing options to services.
A class containing constants representing the names of configuration variables.
const ParserCacheUseJson
Name constant for the ParserCacheUseJson setting, for use with Config::get()
const OldRevisionParserCacheExpireTime
Name constant for the OldRevisionParserCacheExpireTime setting, for use with Config::get()
const CacheEpoch
Name constant for the CacheEpoch setting, for use with Config::get()
Service for creating WikiPage objects.
__construct(BagOStuff $parserCacheBackend, WANObjectCache $revisionOutputCacheBackend, HookContainer $hookContainer, JsonCodec $jsonCodec, IBufferingStatsdDataFactory $stats, LoggerInterface $logger, ServiceOptions $options, TitleFactory $titleFactory, WikiPageFactory $wikiPageFactory)
WANObjectCache $revisionOutputCacheBackend
RevisionOutputCache[] $revisionOutputCaches
getRevisionOutputCache(string $name)
Get a RevisionOutputCache instance by $name.
getParserCache(string $name)
Get a ParserCache instance by $name.
IBufferingStatsdDataFactory $stats
Cache for ParserOutput objects.
Cache for ParserOutput objects corresponding to the latest page revisions.
Definition: ParserCache.php:63
Creates Title objects.
Multi-datacenter aware caching interface.
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.
$cache
Definition: mcc.php:33