MediaWiki REL1_35
LinkCache Class Reference

Cache for article titles (prefixed DB keys) and ids linked from one source. More...

Collaboration diagram for LinkCache:

Public Member Functions

 __construct (TitleFormatter $titleFormatter, WANObjectCache $cache, NamespaceInfo $nsInfo=null)
 
 addBadLinkObj (LinkTarget $target)
 
 addGoodLinkObj ( $id, LinkTarget $target, $len=-1, $redir=null, $revision=0, $model=null, $lang=null)
 Add a link for the title to the link cache.
 
 addGoodLinkObjFromRow (LinkTarget $target, $row)
 Same as above with better interface.
 
 addLinkObj (LinkTarget $nt)
 Add a title to the link cache, return the page_id or zero if non-existent.
 
 clear ()
 Clears cache.
 
 clearBadLink ( $title)
 
 clearLink (LinkTarget $target)
 
 forUpdate ( $update=null)
 General accessor to get/set whether the master DB should be used.
 
 getGoodLinkFieldObj (LinkTarget $target, $field)
 Get a field of a title object from cache.
 
 getGoodLinkID ( $title)
 
 getMutableCacheKeys (WANObjectCache $cache, LinkTarget $t)
 
 invalidateTitle (LinkTarget $title)
 Purge the link cache for a title.
 
 isBadLink ( $title)
 

Static Public Member Functions

static getSelectFields ()
 Fields that LinkCache needs to select.
 
static singleton ()
 Get an instance of this class.
 

Private Member Functions

 fetchPageRow (IDatabase $db, LinkTarget $nt)
 
 isCacheable (LinkTarget $title)
 

Private Attributes

MapCacheLRU $badLinks
 
MapCacheLRU $goodLinks
 
bool $mForUpdate = false
 
NamespaceInfo $nsInfo
 
TitleFormatter $titleFormatter
 
WANObjectCache $wanCache
 
const MAX_SIZE = 10000
 How many Titles to store.
 

Detailed Description

Cache for article titles (prefixed DB keys) and ids linked from one source.

Definition at line 34 of file LinkCache.php.

Constructor & Destructor Documentation

◆ __construct()

LinkCache::__construct ( TitleFormatter  $titleFormatter,
WANObjectCache  $cache,
NamespaceInfo  $nsInfo = null 
)

Definition at line 57 of file LinkCache.php.

References $cache, and wfDeprecated().

Member Function Documentation

◆ addBadLinkObj()

LinkCache::addBadLinkObj ( LinkTarget  $target)
Parameters
LinkTarget$target

Definition at line 190 of file LinkCache.php.

References isBadLink().

Referenced by addLinkObj().

◆ addGoodLinkObj()

LinkCache::addGoodLinkObj (   $id,
LinkTarget  $target,
  $len = -1,
  $redir = null,
  $revision = 0,
  $model = null,
  $lang = null 
)

Add a link for the title to the link cache.

Parameters
int$idPage's ID
LinkTarget$target
int$lenText's length
int | null$redirWhether the page is a redirect
int$revisionLatest revision's ID
string | null$modelLatest revision's content model ID
string | null$langLanguage code of the page, if not the content language

Definition at line 146 of file LinkCache.php.

References $lang.

◆ addGoodLinkObjFromRow()

LinkCache::addGoodLinkObjFromRow ( LinkTarget  $target,
  $row 
)

Same as above with better interface.

Since
1.19
Parameters
LinkTarget$target
stdClass$rowObject which has the fields page_id, page_is_redirect, page_latest and page_content_model

Definition at line 168 of file LinkCache.php.

Referenced by addLinkObj().

◆ addLinkObj()

LinkCache::addLinkObj ( LinkTarget  $nt)

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

Parameters
LinkTarget$ntLinkTarget object to add
Returns
int Page ID or zero

Definition at line 244 of file LinkCache.php.

References $cache, $dbr, addBadLinkObj(), addGoodLinkObjFromRow(), DB_MASTER, DB_REPLICA, fetchPageRow(), MediaWiki\Linker\LinkTarget\getDBkey(), getGoodLinkID(), MediaWiki\Linker\LinkTarget\getNamespace(), isBadLink(), isCacheable(), MediaWiki\Linker\LinkTarget\isExternal(), wfGetDB(), and wfTimestamp().

◆ clear()

LinkCache::clear ( )

Clears cache.

Definition at line 352 of file LinkCache.php.

◆ clearBadLink()

LinkCache::clearBadLink (   $title)
Parameters
string$titlePrefixed DB key

Definition at line 200 of file LinkCache.php.

References $title.

◆ clearLink()

LinkCache::clearLink ( LinkTarget  $target)
Parameters
LinkTarget$target

Definition at line 207 of file LinkCache.php.

◆ fetchPageRow()

LinkCache::fetchPageRow ( IDatabase  $db,
LinkTarget  $nt 
)
private

◆ forUpdate()

LinkCache::forUpdate (   $update = null)

General accessor to get/set whether the master DB should be used.

This used to also set the FOR UPDATE option (locking the rows read in order to avoid link table inconsistency), which was later removed for performance on wikis with a high edit rate.

Parameters
bool | null$update
Returns
bool
Deprecated:
Since 1.34

Definition at line 94 of file LinkCache.php.

References wfSetVar().

◆ getGoodLinkFieldObj()

LinkCache::getGoodLinkFieldObj ( LinkTarget  $target,
  $field 
)

Get a field of a title object from cache.

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

Parameters
LinkTarget$target
string$field('length','redirect','revision','model')
Returns
string|int|null

Definition at line 117 of file LinkCache.php.

◆ getGoodLinkID()

LinkCache::getGoodLinkID (   $title)
Parameters
string$titlePrefixed DB key
Returns
int Page ID or zero

Definition at line 102 of file LinkCache.php.

References $title.

Referenced by addLinkObj().

◆ getMutableCacheKeys()

LinkCache::getMutableCacheKeys ( WANObjectCache  $cache,
LinkTarget  $t 
)
Parameters
WANObjectCache$cache
LinkTarget$t
Returns
string[]
Since
1.28

Definition at line 299 of file LinkCache.php.

References $cache, $t, and isCacheable().

◆ getSelectFields()

static LinkCache::getSelectFields ( )
static

Fields that LinkCache needs to select.

Since
1.28
Returns
array

Definition at line 219 of file LinkCache.php.

References $wgPageLanguageUseDB.

◆ invalidateTitle()

LinkCache::invalidateTitle ( LinkTarget  $title)

Purge the link cache for a title.

Parameters
LinkTarget$title
Since
1.28

Definition at line 340 of file LinkCache.php.

References $cache, $title, and isCacheable().

◆ isBadLink()

LinkCache::isBadLink (   $title)
Parameters
string$titlePrefixed DB key
Returns
bool

Definition at line 130 of file LinkCache.php.

References $title.

Referenced by addBadLinkObj(), and addLinkObj().

◆ isCacheable()

LinkCache::isCacheable ( LinkTarget  $title)
private

◆ singleton()

static LinkCache::singleton ( )
static

Get an instance of this class.

Returns
LinkCache
Deprecated:
since 1.28, use MediaWikiServices instead

Definition at line 79 of file LinkCache.php.

Member Data Documentation

◆ $badLinks

MapCacheLRU LinkCache::$badLinks
private

Definition at line 38 of file LinkCache.php.

◆ $goodLinks

MapCacheLRU LinkCache::$goodLinks
private

Definition at line 36 of file LinkCache.php.

◆ $mForUpdate

bool LinkCache::$mForUpdate = false
private

Definition at line 43 of file LinkCache.php.

◆ $nsInfo

NamespaceInfo LinkCache::$nsInfo
private

Definition at line 49 of file LinkCache.php.

◆ $titleFormatter

TitleFormatter LinkCache::$titleFormatter
private

Definition at line 46 of file LinkCache.php.

◆ $wanCache

WANObjectCache LinkCache::$wanCache
private

Definition at line 40 of file LinkCache.php.

◆ MAX_SIZE

const LinkCache::MAX_SIZE = 10000
private

How many Titles to store.

There are two caches, so the amount actually stored in memory can be up to twice this.

Definition at line 55 of file LinkCache.php.


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