Debian Codegraph @

includes/cache/BacklinkCacheFactory.php

raw symbols SCIP
1 <?php
2 /**
3 * Remember the page that was previously loaded.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Cache
22 */
23
24 namespace MediaWiki\Cache;
25
26 use MediaWiki\Config\ServiceOptions;
27 use MediaWiki\HookContainer\HookContainer;
28 use MediaWiki\Linker\LinksMigration;
29 use MediaWiki\Page\PageReference;
30 use Psr\Log\LoggerInterface;
31 use Wikimedia\ObjectCache\WANObjectCache;
32 use Wikimedia\Rdbms\IConnectionProvider;
33
34 /**
35 * @since 1.37
36 */
37 class BacklinkCacheFactory {
38 /** @var BacklinkCache */
39 private $latestBacklinkCache;
40
41 /** @var WANObjectCache */
42 private $wanCache;
43
44 /** @var HookContainer */
45 private $hookContainer;
46
47 private IConnectionProvider $dbProvider;
48 private ServiceOptions $options;
49 private LinksMigration $linksMigration;
50 private LoggerInterface $logger;
51
52 public function __construct(
53 ServiceOptions $options,
54 LinksMigration $linksMigration,
55 WANObjectCache $wanCache,
56 HookContainer $hookContainer,
57 IConnectionProvider $dbProvider,
58 LoggerInterface $logger
59 ) {
60 $this->options = $options;
61 $this->linksMigration = $linksMigration;
62 $this->wanCache = $wanCache;
63 $this->hookContainer = $hookContainer;
64 $this->dbProvider = $dbProvider;
65 $this->logger = $logger;
66 }
67
68 /**
69 * Returns a BacklinkCache for $page. May re-use previously
70 * created instances.
71 *
72 * Currently, only one cache instance can exist; callers that
73 * need multiple backlink cache objects should keep them in scope.
74 *
75 * @param PageReference $page Page to get a backlink cache for
76 * @return BacklinkCache
77 */
78 public function getBacklinkCache( PageReference $page ): BacklinkCache {
79 if ( !$this->latestBacklinkCache || !$this->latestBacklinkCache->getPage()->isSamePageAs( $page ) ) {
80 $this->latestBacklinkCache = new BacklinkCache(
81 $this->options,
82 $this->linksMigration,
83 $this->wanCache,
84 $this->hookContainer,
85 $this->dbProvider,
86 $this->logger,
87 $page
88 );
89 }
90 return $this->latestBacklinkCache;
91 }
92 }