MediaWiki master
ParserCacheFactory.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Parser;
23
30use Psr\Log\LoggerInterface;
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
73 private GlobalIdGenerator $globalIdGenerator;
74
76 private $parserCaches = [];
77
79 private $revisionOutputCaches = [];
80
82 private $options;
83
87 public const CONSTRUCTOR_OPTIONS = [
91 ];
92
105 public function __construct(
106 BagOStuff $parserCacheBackend,
107 WANObjectCache $revisionOutputCacheBackend,
108 HookContainer $hookContainer,
109 JsonCodec $jsonCodec,
110 StatsFactory $stats,
111 LoggerInterface $logger,
112 ServiceOptions $options,
113 TitleFactory $titleFactory,
114 WikiPageFactory $wikiPageFactory,
115 GlobalIdGenerator $globalIdGenerator
116 ) {
117 $this->parserCacheBackend = $parserCacheBackend;
118 $this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
119 $this->hookContainer = $hookContainer;
120 $this->jsonCodec = $jsonCodec;
121 $this->stats = $stats;
122 $this->logger = $logger;
123
124 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
125 $this->options = $options;
126 $this->titleFactory = $titleFactory;
127 $this->wikiPageFactory = $wikiPageFactory;
128 $this->globalIdGenerator = $globalIdGenerator;
129 }
130
136 public function getParserCache( string $name ): ParserCache {
137 if ( !isset( $this->parserCaches[$name] ) ) {
138 $this->logger->debug( "Creating ParserCache instance for {$name}" );
139 $cache = new ParserCache(
140 $name,
141 $this->parserCacheBackend,
142 $this->options->get( MainConfigNames::CacheEpoch ),
143 $this->hookContainer,
144 $this->jsonCodec,
145 $this->stats,
146 $this->logger,
147 $this->titleFactory,
148 $this->wikiPageFactory,
149 $this->globalIdGenerator
150 );
151
152 $filterConfig = $this->options->get( MainConfigNames::ParserCacheFilterConfig );
153
154 if ( isset( $filterConfig[$name] ) ) {
155 $filter = new ParserCacheFilter( $filterConfig[$name] );
156 $cache->setFilter( $filter );
157 }
158
159 $this->parserCaches[$name] = $cache;
160 }
161 return $this->parserCaches[$name];
162 }
163
169 public function getRevisionOutputCache( string $name ): RevisionOutputCache {
170 if ( !isset( $this->revisionOutputCaches[$name] ) ) {
171 $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
172 $cache = new RevisionOutputCache(
173 $name,
174 $this->revisionOutputCacheBackend,
176 $this->options->get( MainConfigNames::CacheEpoch ),
177 $this->jsonCodec,
178 $this->stats,
179 $this->logger,
180 $this->globalIdGenerator
181 );
182
183 $this->revisionOutputCaches[$name] = $cache;
184 }
185 return $this->revisionOutputCaches[$name];
186 }
187}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
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 corresponding to the latest page revisions.
Cache for ParserOutput objects.
Creates Title objects.
Abstract class for any ephemeral data store.
Definition BagOStuff.php:89
Multi-datacenter aware caching interface.
StatsFactory Implementation.
Class for getting statistically unique IDs without a central coordinator.