MediaWiki master
ParserCacheFactory.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Parser;
23
24use BagOStuff;
31use ParserCache;
32use Psr\Log\LoggerInterface;
36
43
45 public const DEFAULT_NAME = 'pcache';
46
48 public const DEFAULT_RCACHE_NAME = 'rcache';
49
51 private $parserCacheBackend;
52
54 private $revisionOutputCacheBackend;
55
57 private $hookContainer;
58
60 private $jsonCodec;
61
63 private $stats;
64
66 private $logger;
67
69 private $titleFactory;
70
72 private $wikiPageFactory;
73
74 private GlobalIdGenerator $globalIdGenerator;
75
77 private $parserCaches = [];
78
80 private $revisionOutputCaches = [];
81
83 private $options;
84
88 public const CONSTRUCTOR_OPTIONS = [
92 ];
93
106 public function __construct(
107 BagOStuff $parserCacheBackend,
108 WANObjectCache $revisionOutputCacheBackend,
109 HookContainer $hookContainer,
110 JsonCodec $jsonCodec,
111 StatsFactory $stats,
112 LoggerInterface $logger,
113 ServiceOptions $options,
114 TitleFactory $titleFactory,
115 WikiPageFactory $wikiPageFactory,
116 GlobalIdGenerator $globalIdGenerator
117 ) {
118 $this->parserCacheBackend = $parserCacheBackend;
119 $this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
120 $this->hookContainer = $hookContainer;
121 $this->jsonCodec = $jsonCodec;
122 $this->stats = $stats;
123 $this->logger = $logger;
124
125 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
126 $this->options = $options;
127 $this->titleFactory = $titleFactory;
128 $this->wikiPageFactory = $wikiPageFactory;
129 $this->globalIdGenerator = $globalIdGenerator;
130 }
131
137 public function getParserCache( string $name ): ParserCache {
138 if ( !isset( $this->parserCaches[$name] ) ) {
139 $this->logger->debug( "Creating ParserCache instance for {$name}" );
140 $cache = new ParserCache(
141 $name,
142 $this->parserCacheBackend,
143 $this->options->get( MainConfigNames::CacheEpoch ),
144 $this->hookContainer,
145 $this->jsonCodec,
146 $this->stats,
147 $this->logger,
148 $this->titleFactory,
149 $this->wikiPageFactory,
150 $this->globalIdGenerator
151 );
152
153 $filterConfig = $this->options->get( MainConfigNames::ParserCacheFilterConfig );
154
155 if ( isset( $filterConfig[$name] ) ) {
156 $filter = new ParserCacheFilter( $filterConfig[$name] );
157 $cache->setFilter( $filter );
158 }
159
160 $this->parserCaches[$name] = $cache;
161 }
162 return $this->parserCaches[$name];
163 }
164
170 public function getRevisionOutputCache( string $name ): RevisionOutputCache {
171 if ( !isset( $this->revisionOutputCaches[$name] ) ) {
172 $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
173 $cache = new RevisionOutputCache(
174 $name,
175 $this->revisionOutputCacheBackend,
177 $this->options->get( MainConfigNames::CacheEpoch ),
178 $this->jsonCodec,
179 $this->stats,
180 $this->logger,
181 $this->globalIdGenerator
182 );
183
184 $this->revisionOutputCaches[$name] = $cache;
185 }
186 return $this->revisionOutputCaches[$name];
187 }
188}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Class representing a cache/ephemeral data store.
Definition BagOStuff.php:85
A class for passing options to services.
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
A class containing constants representing the names of configuration variables.
const OldRevisionParserCacheExpireTime
Name constant for the OldRevisionParserCacheExpireTime setting, for use with Config::get()
const ParserCacheFilterConfig
Name constant for the ParserCacheFilterConfig 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, StatsFactory $stats, LoggerInterface $logger, ServiceOptions $options, TitleFactory $titleFactory, WikiPageFactory $wikiPageFactory, GlobalIdGenerator $globalIdGenerator)
getParserCache(string $name)
Get a ParserCache instance by $name.
getRevisionOutputCache(string $name)
Get a RevisionOutputCache instance by $name.
Cache for ParserOutput objects.
Creates Title objects.
Cache for ParserOutput objects corresponding to the latest page revisions.
Multi-datacenter aware caching interface.
StatsFactory Implementation.
Class for getting statistically unique IDs without a central coordinator.