1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Cache Parser
*/
namespace MediaWiki\Parser;
use BagOStuff;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Json\JsonCodec;
use MediaWiki\MainConfigNames;
use MediaWiki\Page\WikiPageFactory;
use MediaWiki\Title\TitleFactory;
use ParserCache;
use Psr\Log\LoggerInterface;
use WANObjectCache;
use Wikimedia\Stats\StatsFactory;
use Wikimedia\UUID\GlobalIdGenerator;
/**
* Returns an instance of the ParserCache by its name.
* @since 1.36
* @package MediaWiki\Parser
*/
class ParserCacheFactory {
/** @var string name of ParserCache for the default parser */
public const DEFAULT_NAME = 'pcache';
/** @var string name of RevisionOutputCache for the default parser */
public const DEFAULT_RCACHE_NAME = 'rcache';
/** @var BagOStuff */
private $parserCacheBackend;
/** @var WANObjectCache */
private $revisionOutputCacheBackend;
/** @var HookContainer */
private $hookContainer;
/** @var JsonCodec */
private $jsonCodec;
/** @var StatsFactory */
private $stats;
/** @var LoggerInterface */
private $logger;
/** @var TitleFactory */
private $titleFactory;
/** @var WikiPageFactory */
private $wikiPageFactory;
private GlobalIdGenerator $globalIdGenerator;
/** @var ParserCache[] */
private $parserCaches = [];
/** @var RevisionOutputCache[] */
private $revisionOutputCaches = [];
/** @var ServiceOptions */
private $options;
/**
* @internal
*/
public const CONSTRUCTOR_OPTIONS = [
MainConfigNames::CacheEpoch,
MainConfigNames::ParserCacheFilterConfig,
MainConfigNames::OldRevisionParserCacheExpireTime,
];
/**
* @param BagOStuff $parserCacheBackend
* @param WANObjectCache $revisionOutputCacheBackend
* @param HookContainer $hookContainer
* @param JsonCodec $jsonCodec
* @param StatsFactory $stats
* @param LoggerInterface $logger
* @param ServiceOptions $options
* @param TitleFactory $titleFactory
* @param WikiPageFactory $wikiPageFactory
* @param GlobalIdGenerator $globalIdGenerator
*/
public function __construct(
BagOStuff $parserCacheBackend,
WANObjectCache $revisionOutputCacheBackend,
HookContainer $hookContainer,
JsonCodec $jsonCodec,
StatsFactory $stats,
LoggerInterface $logger,
ServiceOptions $options,
TitleFactory $titleFactory,
WikiPageFactory $wikiPageFactory,
GlobalIdGenerator $globalIdGenerator
) {
$this->parserCacheBackend = $parserCacheBackend;
$this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
$this->hookContainer = $hookContainer;
$this->jsonCodec = $jsonCodec;
$this->stats = $stats;
$this->logger = $logger;
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->options = $options;
$this->titleFactory = $titleFactory;
$this->wikiPageFactory = $wikiPageFactory;
$this->globalIdGenerator = $globalIdGenerator;
}
/**
* Get a ParserCache instance by $name.
* @param string $name
* @return ParserCache
*/
public function getParserCache( string $name ): ParserCache {
if ( !isset( $this->parserCaches[$name] ) ) {
$this->logger->debug( "Creating ParserCache instance for {$name}" );
$cache = new ParserCache(
$name,
$this->parserCacheBackend,
$this->options->get( MainConfigNames::CacheEpoch ),
$this->hookContainer,
$this->jsonCodec,
$this->stats,
$this->logger,
$this->titleFactory,
$this->wikiPageFactory,
$this->globalIdGenerator
);
$filterConfig = $this->options->get( MainConfigNames::ParserCacheFilterConfig );
if ( isset( $filterConfig[$name] ) ) {
$filter = new ParserCacheFilter( $filterConfig[$name] );
$cache->setFilter( $filter );
}
$this->parserCaches[$name] = $cache;
}
return $this->parserCaches[$name];
}
/**
* Get a RevisionOutputCache instance by $name.
* @param string $name
* @return RevisionOutputCache
*/
public function getRevisionOutputCache( string $name ): RevisionOutputCache {
if ( !isset( $this->revisionOutputCaches[$name] ) ) {
$this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
$cache = new RevisionOutputCache(
$name,
$this->revisionOutputCacheBackend,
$this->options->get( MainConfigNames::OldRevisionParserCacheExpireTime ),
$this->options->get( MainConfigNames::CacheEpoch ),
$this->jsonCodec,
$this->stats,
$this->logger,
$this->globalIdGenerator
);
$this->revisionOutputCaches[$name] = $cache;
}
return $this->revisionOutputCaches[$name];
}
}
|