MediaWiki master
MediaWiki\Page\LinkCache Class Reference

Page existence and metadata cache. More...

Inherits LoggerAwareInterface.

Collaboration diagram for MediaWiki\Page\LinkCache:

Public Member Functions

 __construct (TitleFormatter $titleFormatter, WANObjectCache $cache, NamespaceInfo $nsInfo, ?IConnectionProvider $dbProvider=null)
 addBadLinkObj ( $page, int $queryFlags=IDBAccessObject::READ_NORMAL)
 Add information about a missing page to the process cache.
 addGoodLinkObjFromRow ( $page, stdClass $row, int $queryFlags=IDBAccessObject::READ_NORMAL)
 Add information about an existing page to the process cache.
 addLinkObj ( $page, int $queryFlags=IDBAccessObject::READ_NORMAL)
 Add a title to the link cache, return the page_id or zero if non-existent.
 clear ()
 clearBadLink ( $page)
 Clear information about a page being missing from the process cache.
 clearLink ( $page)
 Clear information about a page from the process cache.
 getGoodLinkFieldObj ( $page, string $field)
 Get the field of a page known to the process cache.
 getGoodLinkID ( $page)
 Get the ID of a page known to the process cache.
 getGoodLinkRow (int $ns, string $dbkey, ?callable $fetchCallback=null, int $queryFlags=IDBAccessObject::READ_NORMAL)
 Returns the row for the page if the page exists (subject to race conditions).
 invalidateTitle ( $page)
 Purge the persistent link cache for a title.
 isBadLink ( $page)
 Check if a page is known to be missing based on the process cache.
 preloadPersistentCache (array $pages, string $fname, LinkBatchFactory $linkBatchFactory)
 setLogger (LoggerInterface $logger)

Static Public Member Functions

static getSelectFields ()
 Fields that LinkCache needs to select.

Detailed Description

Page existence and metadata cache.

This is exists primarily to reduce heavy database load from the Parser when rendering each individual outgoing link and template transclusion when parsing wikitext.

See the architecture doc at docs/LinkCache.md for more information.

To create a batch, you can use the following code:

$titles = [];
foreach ( [ 'Main Page', 'Project:Help' ] as $page ) {
$titles[] = Title::newFromText( $page );
}
$linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
$linkBatchFactory->newLinkBatch( $titles )->setCaller( __METHOD__ )->execute();
static getInstance()
Returns the global default instance of the top level service locator.
See also
MediaWiki\Page\LinkBatchFactory
MediaWiki\Page\LinkBatch
Since
1.1

Definition at line 52 of file LinkCache.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Page\LinkCache::__construct ( TitleFormatter $titleFormatter,
WANObjectCache $cache,
NamespaceInfo $nsInfo,
?IConnectionProvider $dbProvider = null )
Parameters
TitleFormatter$titleFormatter
WANObjectCache$cache
NamespaceInfo$nsInfo
IConnectionProvider | null$dbProviderUse null when no database is set up, for example on installation

Definition at line 80 of file LinkCache.php.

Member Function Documentation

◆ addBadLinkObj()

MediaWiki\Page\LinkCache::addBadLinkObj ( $page,
int $queryFlags = IDBAccessObject::READ_NORMAL )

Add information about a missing page to the process cache.

Callers must set the READ_LATEST flag if the row came from a DB_PRIMARY source. However, the use of such data is highly discouraged; most callers rely on seeing consistent DB_REPLICA data (e.g. REPEATABLE-READ point-in-time snapshots) and the accidental use of DB_PRIMARY data via LinkCache is prone to causing anomalies.

Parameters
LinkTarget | PageReference | array$pageThe page to set cached info for. Can be given as an object or an associative array containing the page_namespace and page_title fields. In MediaWiki 1.36 and earlier, only LinkTarget was accepted.
int$queryFlagsThe query flags used to retrieve the row, IDBAccessObject::READ_*

Definition at line 298 of file LinkCache.php.

Referenced by MediaWiki\Parser\Parser\defaultFetchTemplate().

◆ addGoodLinkObjFromRow()

MediaWiki\Page\LinkCache::addGoodLinkObjFromRow ( $page,
stdClass $row,
int $queryFlags = IDBAccessObject::READ_NORMAL )

Add information about an existing page to the process cache.

Callers must set the READ_LATEST flag if the row came from a DB_PRIMARY source. However, the use of such data is highly discouraged; most callers rely on seeing consistent DB_REPLICA data (e.g. REPEATABLE-READ point-in-time snapshots) and the accidental use of DB_PRIMARY data via LinkCache is prone to causing anomalies.

Parameters
LinkTarget | PageReference | array$pageThe page to set cached info for. Can be given as an object or an associative array containing the page_namespace and page_title fields. In MediaWiki 1.36 and earlier, only LinkTarget was accepted.
stdClass$rowObject which has all fields returned by getSelectFields().
int$queryFlagsThe query flags used to retrieve the row, IDBAccessObject::READ_*
Since
1.19

Definition at line 265 of file LinkCache.php.

◆ addLinkObj()

MediaWiki\Page\LinkCache::addLinkObj ( $page,
int $queryFlags = IDBAccessObject::READ_NORMAL )

Add a title to the link cache, return the page_id or zero if non-existent.

This causes the link to be looked up in the database if it is not yet cached.

Deprecated
since 1.37, use PageStore::getPageForLink() instead.
Parameters
LinkTarget | PageReference | array$pageThe page to load. Can be given as an object or an associative array containing the page_namespace and page_title fields. In MediaWiki 1.36 and earlier, only LinkTarget was accepted.
int$queryFlagsIDBAccessObject::READ_XXX
Returns
int Page ID or zero

Definition at line 381 of file LinkCache.php.

References getGoodLinkRow().

◆ clear()

MediaWiki\Page\LinkCache::clear ( )

Definition at line 643 of file LinkCache.php.

◆ clearBadLink()

MediaWiki\Page\LinkCache::clearBadLink ( $page)

Clear information about a page being missing from the process cache.

Parameters
LinkTarget | PageReference | array | string$pageThe page to clear cached info for, as an object, an array containing the page_namespace and page_title fields, or a prefixed DB key. In MediaWiki 1.36 and earlier, only a string was accepted. In MediaWiki 1.36 and earlier, only a string was accepted.

Definition at line 315 of file LinkCache.php.

◆ clearLink()

MediaWiki\Page\LinkCache::clearLink ( $page)

Clear information about a page from the process cache.

Parameters
LinkTarget | PageReference | array$pageThe page to clear cached info for. Can be given as an object or an associative array containing the page_namespace and page_title fields. In MediaWiki 1.36 and earlier, only LinkTarget was accepted.

Definition at line 335 of file LinkCache.php.

Referenced by invalidateTitle().

◆ getGoodLinkFieldObj()

MediaWiki\Page\LinkCache::getGoodLinkFieldObj ( $page,
string $field )

Get the field of a page known to the process cache.

If this link is not a cached good title, it will return NULL.

Parameters
LinkTarget | PageReference | array$pageThe page to get cached info for. Can be given as an object or an associative array containing the page_namespace and page_title fields. In MediaWiki 1.36 and earlier, only LinkTarget was accepted.
string$field( 'id', 'length', 'redirect', 'revision', 'model', 'lang' )
Returns
string|int|null The field value, or null if the page was not cached or does not exist or is not a proper page (e.g. a special page or interwiki link).

Definition at line 191 of file LinkCache.php.

◆ getGoodLinkID()

MediaWiki\Page\LinkCache::getGoodLinkID ( $page)

Get the ID of a page known to the process cache.

Parameters
LinkTarget | PageReference | array | string$pageThe page to get the ID for, as an object, an array containing the page_namespace and page_title fields, or a prefixed DB key. In MediaWiki 1.36 and earlier, only a string was accepted.
Returns
int Page ID, or zero if the page was not cached or does not exist or is not a proper page (e.g. a special page or an interwiki link).

Definition at line 163 of file LinkCache.php.

◆ getGoodLinkRow()

MediaWiki\Page\LinkCache::getGoodLinkRow ( int $ns,
string $dbkey,
?callable $fetchCallback = null,
int $queryFlags = IDBAccessObject::READ_NORMAL )

Returns the row for the page if the page exists (subject to race conditions).

The row will be returned from local cache or WAN cache if possible, or it will be looked up using the callback provided.

Parameters
int$ns
string$dbkey
callable | null$fetchCallbackA callback that will retrieve the link row with the signature ( IReadableDatabase $db, int $ns, string $dbkey, array $queryOptions ): ?stdObj.
int$queryFlagsIDBAccessObject::READ_XXX
Returns
stdClass|null
Access: internal
for use by PageStore. Other code should use a PageLookup instead.

Definition at line 468 of file LinkCache.php.

Referenced by addLinkObj().

◆ getSelectFields()

MediaWiki\Page\LinkCache::getSelectFields ( )
static

Fields that LinkCache needs to select.

Since
1.28
Returns
array

Definition at line 348 of file LinkCache.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\MainConfigNames\PageLanguageUseDB, and MediaWiki\Page\PageStoreRecord\REQUIRED_FIELDS.

Referenced by MediaWiki\Page\LinkBatch\doQuery().

◆ invalidateTitle()

MediaWiki\Page\LinkCache::invalidateTitle ( $page)

Purge the persistent link cache for a title.

Parameters
LinkTarget | PageReference$pageIn MediaWiki 1.36 and earlier, only LinkTarget was accepted.
Since
1.28

Definition at line 634 of file LinkCache.php.

References clearLink().

◆ isBadLink()

MediaWiki\Page\LinkCache::isBadLink ( $page)

Check if a page is known to be missing based on the process cache.

Parameters
LinkTarget | PageReference | array | string$pageThe page to get cached info for, as an object, an array containing the page_namespace and page_title fields, or a prefixed DB key. In MediaWiki 1.36 and earlier, only a string was accepted. In MediaWiki 1.36 and earlier, only a string was accepted.
Returns
bool Whether the page is known to be missing based on the process cache

Definition at line 238 of file LinkCache.php.

◆ preloadPersistentCache()

MediaWiki\Page\LinkCache::preloadPersistentCache ( array $pages,
string $fname,
LinkBatchFactory $linkBatchFactory )
Access: internal
For use only in LinkBatchFactory::preloadPersistentCache
Parameters
string[]$pages

Definition at line 577 of file LinkCache.php.

◆ setLogger()

MediaWiki\Page\LinkCache::setLogger ( LoggerInterface $logger)

Definition at line 94 of file LinkCache.php.


The documentation for this class was generated from the following file: