Debian Codegraph @

includes/parser/ParserCacheFilter.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Cache Parser
20 */
21
22 namespace MediaWiki\Parser;
23
24 use MediaWiki\Page\PageRecord;
25
26 /**
27 * Filter that decides whether a ParserOutput object should be stored in the
28 * ParserCache or not. Can be used tweak tradeoffs between storage space and
29 * response latency.
30 *
31 * @since 1.42
32 * @package MediaWiki\Parser
33 */
34 class ParserCacheFilter {
35
36 /**
37 * @see MainConfigSchema::ParserCacheFilterConfig
38 */
39 private array $config;
40
41 /**
42 * @param array[] $config See MainConfigSchema::ParserCacheFilterConfig.
43 */
44 public function __construct( array $config ) {
45 $this->config = $config;
46 }
47
48 public function shouldCache(
49 ParserOutput $output,
50 PageRecord $page,
51 ParserOptions $options
52 ): bool {
53 $ns = $page->getNamespace();
54 $cpuMin = $this->config[ $ns ]['minCpuTime']
55 ?? ( $this->config['default']['minCpuTime'] ?? 0 );
56
57 $cpuTime = $output->getTimeProfile( 'cpu' );
58
59 if ( $cpuTime !== null && $cpuTime < $cpuMin ) {
60 return false;
61 }
62
63 return true;
64 }
65
66 }