MediaWiki  master
ParserCacheFactory.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Parser;
23 
24 use BagOStuff;
32 use ParserCache;
33 use Psr\Log\LoggerInterface;
34 use WANObjectCache;
35 
42 
44  public const DEFAULT_NAME = 'pcache';
45 
47  public const DEFAULT_RCACHE_NAME = 'rcache';
48 
50  private $parserCacheBackend;
51 
53  private $revisionOutputCacheBackend;
54 
56  private $hookContainer;
57 
59  private $jsonCodec;
60 
62  private $stats;
63 
65  private $logger;
66 
68  private $titleFactory;
69 
71  private $wikiPageFactory;
72 
74  private $parserCaches = [];
75 
77  private $revisionOutputCaches = [];
78 
80  private $options;
81 
85  public const CONSTRUCTOR_OPTIONS = [
88  ];
89 
101  public function __construct(
102  BagOStuff $parserCacheBackend,
103  WANObjectCache $revisionOutputCacheBackend,
104  HookContainer $hookContainer,
105  JsonCodec $jsonCodec,
107  LoggerInterface $logger,
108  ServiceOptions $options,
109  TitleFactory $titleFactory,
110  WikiPageFactory $wikiPageFactory
111  ) {
112  $this->parserCacheBackend = $parserCacheBackend;
113  $this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
114  $this->hookContainer = $hookContainer;
115  $this->jsonCodec = $jsonCodec;
116  $this->stats = $stats;
117  $this->logger = $logger;
118 
119  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
120  $this->options = $options;
121  $this->titleFactory = $titleFactory;
122  $this->wikiPageFactory = $wikiPageFactory;
123  }
124 
130  public function getParserCache( string $name ): ParserCache {
131  if ( !isset( $this->parserCaches[$name] ) ) {
132  $this->logger->debug( "Creating ParserCache instance for {$name}" );
133  $cache = new ParserCache(
134  $name,
135  $this->parserCacheBackend,
136  $this->options->get( MainConfigNames::CacheEpoch ),
137  $this->hookContainer,
138  $this->jsonCodec,
139  $this->stats,
140  $this->logger,
141  $this->titleFactory,
142  $this->wikiPageFactory
143  );
144 
145  $this->parserCaches[$name] = $cache;
146  }
147  return $this->parserCaches[$name];
148  }
149 
155  public function getRevisionOutputCache( string $name ): RevisionOutputCache {
156  if ( !isset( $this->revisionOutputCaches[$name] ) ) {
157  $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
158  $cache = new RevisionOutputCache(
159  $name,
160  $this->revisionOutputCacheBackend,
162  $this->options->get( MainConfigNames::CacheEpoch ),
163  $this->jsonCodec,
164  $this->stats,
165  $this->logger
166  );
167 
168  $this->revisionOutputCaches[$name] = $cache;
169  }
170  return $this->revisionOutputCaches[$name];
171  }
172 }
if(!defined('MW_SETUP_CALLBACK'))
Definition: WebStart.php:88
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.
Creates Title objects.
Cache for ParserOutput objects corresponding to the latest page revisions.
Definition: ParserCache.php:64
Multi-datacenter aware caching interface.
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.