MediaWiki  master
ParserCacheFactory.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Parser;
23 
24 use BagOStuff;
29 use ParserCache;
30 use Psr\Log\LoggerInterface;
31 use WANObjectCache;
32 
39 
41  public const DEFAULT_NAME = 'pcache';
42 
45 
48 
50  private $hookContainer;
51 
53  private $jsonCodec;
54 
56  private $stats;
57 
59  private $logger;
60 
62  private $parserCaches = [];
63 
65  private $revisionOutputCaches = [];
66 
68  private $options;
69 
73  public const CONSTRUCTOR_OPTIONS = [
74  'ParserCacheUseJson', // Temporary feature flag, remove before 1.36 is released.
75  'CacheEpoch',
76  'OldRevisionParserCacheExpireTime',
77  ];
78 
88  public function __construct(
91  HookContainer $hookContainer,
92  JsonCodec $jsonCodec,
94  LoggerInterface $logger,
95  ServiceOptions $options
96  ) {
97  $this->parserCacheBackend = $parserCacheBackend;
98  $this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
99  $this->hookContainer = $hookContainer;
100  $this->jsonCodec = $jsonCodec;
101  $this->stats = $stats;
102  $this->logger = $logger;
103 
104  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
105  $this->options = $options;
106  }
107 
113  public function getParserCache( string $name ) : ParserCache {
114  if ( !isset( $this->parserCaches[$name] ) ) {
115  $this->logger->debug( "Creating ParserCache instance for {$name}" );
116  $cache = new ParserCache(
117  $name,
118  $this->parserCacheBackend,
119  $this->options->get( 'CacheEpoch' ),
120  $this->hookContainer,
121  $this->jsonCodec,
122  $this->stats,
123  $this->logger,
124  $this->options->get( 'ParserCacheUseJson' )
125  );
126 
127  $this->parserCaches[$name] = $cache;
128  }
129  return $this->parserCaches[$name];
130  }
131 
137  public function getRevisionOutputCache( string $name ) : RevisionOutputCache {
138  if ( !isset( $this->revisionOutputCaches[$name] ) ) {
139  $this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
141  $name,
142  $this->revisionOutputCacheBackend,
143  $this->options->get( 'OldRevisionParserCacheExpireTime' ),
144  $this->options->get( 'CacheEpoch' ),
145  $this->jsonCodec,
146  $this->stats,
147  $this->logger
148  );
149 
150  $this->revisionOutputCaches[$name] = $cache;
151  }
152  return $this->revisionOutputCaches[$name];
153  }
154 }
Parser\ParserCacheFactory\$hookContainer
HookContainer $hookContainer
Definition: ParserCacheFactory.php:50
MediaWiki\Parser
Definition: ParserCacheFactory.php:22
Parser\ParserCacheFactory\$revisionOutputCacheBackend
WANObjectCache $revisionOutputCacheBackend
Definition: ParserCacheFactory.php:47
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:86
Parser\ParserCacheFactory\$logger
LoggerInterface $logger
Definition: ParserCacheFactory.php:59
Parser\ParserCacheFactory
Definition: ParserCacheFactory.php:38
Parser\ParserCacheFactory\$parserCacheBackend
BagOStuff $parserCacheBackend
Definition: ParserCacheFactory.php:40
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:27
Parser\ParserCacheFactory\$revisionOutputCaches
RevisionOutputCache[] $revisionOutputCaches
Definition: ParserCacheFactory.php:65
Parser\ParserCacheFactory\$parserCaches
ParserCache[] $parserCaches
Definition: ParserCacheFactory.php:62
Parser\ParserCacheFactory\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition: ParserCacheFactory.php:73
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:125
Parser\ParserCacheFactory\$stats
IBufferingStatsdDataFactory $stats
Definition: ParserCacheFactory.php:56
Parser\ParserCacheFactory\getRevisionOutputCache
getRevisionOutputCache(string $name)
Get a RevisionOutputCache instance by $name.
Definition: ParserCacheFactory.php:137
IBufferingStatsdDataFactory
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.
Definition: IBufferingStatsdDataFactory.php:13
Parser\RevisionOutputCache
Cache for ParserOutput objects.
Definition: RevisionOutputCache.php:44
$cache
$cache
Definition: mcc.php:33
Parser\ParserCacheFactory\getParserCache
getParserCache(string $name)
Get a ParserCache instance by $name.
Definition: ParserCacheFactory.php:113
ParserCache
Cache for ParserOutput objects corresponding to the latest page revisions.
Definition: ParserCache.php:61
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
MediaWiki\Json\JsonCodec
Definition: JsonCodec.php:36
Parser\ParserCacheFactory\__construct
__construct(BagOStuff $parserCacheBackend, WANObjectCache $revisionOutputCacheBackend, HookContainer $hookContainer, JsonCodec $jsonCodec, IBufferingStatsdDataFactory $stats, LoggerInterface $logger, ServiceOptions $options)
Definition: ParserCacheFactory.php:88
Parser\ParserCacheFactory\$options
ServiceOptions $options
Definition: ParserCacheFactory.php:68
Parser\ParserCacheFactory\$jsonCodec
JsonCodec $jsonCodec
Definition: ParserCacheFactory.php:53