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 
47  private $parserCacheBackend;
48 
50  private $revisionOutputCacheBackend;
51 
53  private $hookContainer;
54 
56  private $jsonCodec;
57 
59  private $stats;
60 
62  private $logger;
63 
65  private $titleFactory;
66 
68  private $wikiPageFactory;
69 
71  private $parserCaches = [];
72 
74  private $revisionOutputCaches = [];
75 
77  private $options;
78 
82  public const CONSTRUCTOR_OPTIONS = [
85  ];
86 
98  public function __construct(
99  BagOStuff $parserCacheBackend,
100  WANObjectCache $revisionOutputCacheBackend,
101  HookContainer $hookContainer,
102  JsonCodec $jsonCodec,
104  LoggerInterface $logger,
105  ServiceOptions $options,
106  TitleFactory $titleFactory,
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( MainConfigNames::CacheEpoch ),
134  $this->hookContainer,
135  $this->jsonCodec,
136  $this->stats,
137  $this->logger,
138  $this->titleFactory,
139  $this->wikiPageFactory
140  );
141 
142  $this->parserCaches[$name] = $cache;
143  }
144  return $this->parserCaches[$name];
145  }
146 
152  public function getRevisionOutputCache( string $name ): RevisionOutputCache {
153  if ( !isset( $this->revisionOutputCaches[$name] ) ) {
154  $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
156  $name,
157  $this->revisionOutputCacheBackend,
159  $this->options->get( MainConfigNames::CacheEpoch ),
160  $this->jsonCodec,
161  $this->stats,
162  $this->logger
163  );
164 
165  $this->revisionOutputCaches[$name] = $cache;
166  }
167  return $this->revisionOutputCaches[$name];
168  }
169 }
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:85
A class for passing options to services.
A class containing constants representing the names of configuration variables.
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)
getRevisionOutputCache(string $name)
Get a RevisionOutputCache instance by $name.
getParserCache(string $name)
Get a ParserCache instance by $name.
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