MediaWiki master
ParserCacheFactory.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
16use Psr\Log\LoggerInterface;
21
28
30 public const DEFAULT_NAME = 'pcache';
31
33 public const DEFAULT_RCACHE_NAME = 'rcache';
34
36 private $parserCaches = [];
37
39 private $revisionOutputCaches = [];
40
44 public const CONSTRUCTOR_OPTIONS = [
48 ];
49
50 public function __construct(
51 private readonly BagOStuff $parserCacheBackend,
52 private readonly WANObjectCache $revisionOutputCacheBackend,
53 private readonly HookContainer $hookContainer,
54 private readonly JsonCodec $jsonCodec,
55 private readonly StatsFactory $stats,
56 private readonly LoggerInterface $logger,
57 private readonly ServiceOptions $options,
58 private readonly TitleFactory $titleFactory,
59 private readonly WikiPageFactory $wikiPageFactory,
60 private readonly GlobalIdGenerator $globalIdGenerator,
61 ) {
62 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
63 }
64
70 public function getParserCache( string $name ): ParserCache {
71 if ( !isset( $this->parserCaches[$name] ) ) {
72 $this->logger->debug( "Creating ParserCache instance for {$name}" );
73 $cache = new ParserCache(
74 $name,
75 $this->parserCacheBackend,
76 $this->options->get( MainConfigNames::CacheEpoch ),
77 $this->hookContainer,
78 $this->jsonCodec,
79 $this->stats,
80 $this->logger,
81 $this->titleFactory,
82 $this->wikiPageFactory,
83 $this->globalIdGenerator
84 );
85
86 $filterConfig = $this->options->get( MainConfigNames::ParserCacheFilterConfig );
87
88 if ( isset( $filterConfig[$name] ) ) {
89 $filter = new ParserCacheFilter( $filterConfig[$name] );
90 $cache->setFilter( $filter );
91 }
92
93 $this->parserCaches[$name] = $cache;
94 }
95 return $this->parserCaches[$name];
96 }
97
103 public function getRevisionOutputCache( string $name ): RevisionOutputCache {
104 if ( !isset( $this->revisionOutputCaches[$name] ) ) {
105 $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
106 $cache = new RevisionOutputCache(
107 $name,
108 $this->revisionOutputCacheBackend,
110 $this->options->get( MainConfigNames::CacheEpoch ),
111 $this->jsonCodec,
112 $this->stats,
113 $this->logger,
114 $this->globalIdGenerator
115 );
116
117 $this->revisionOutputCaches[$name] = $cache;
118 }
119 return $this->revisionOutputCaches[$name];
120 }
121}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
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 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(private readonly BagOStuff $parserCacheBackend, private readonly WANObjectCache $revisionOutputCacheBackend, private readonly HookContainer $hookContainer, private readonly JsonCodec $jsonCodec, private readonly StatsFactory $stats, private readonly LoggerInterface $logger, private readonly ServiceOptions $options, private readonly TitleFactory $titleFactory, private readonly WikiPageFactory $wikiPageFactory, private readonly 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:73
Multi-datacenter aware caching interface.
This is the primary interface for validating metrics definitions, caching defined metrics,...
Class for getting statistically unique IDs without a central coordinator.