Wikia code/includes/LinkCache.php
< Wikia code | includes
This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date. The information shown below refers to the now unmaintained 1.16 MediaWiki release. The current stable release number is 1.42.3. |
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\LinkCache.php 2011-07-18 22:31:28.393554700 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\LinkCache.php 2011-08-17 15:28:46.786132800 +0100
@@ -5,11 +5,8 @@
* @ingroup Cache
*/
class LinkCache {
- // Increment $mClassVer whenever old serialized versions of this class
- // becomes incompatible with the new version.
- /* private */ var $mClassVer = 4;
- /* private */ var $mGoodLinks, $mBadLinks;
+ /* private */ var $mGoodLinks, $mBadLinks, $mGoodLinkFields;
/* private */ var $mForUpdate;
/**
@@ -37,12 +34,19 @@
return wfSetVar( $this->mForUpdate, $update );
}
+ /*
+ * Get ID for Title from cache.
+ * @param String $title
+ */
public function getGoodLinkID( $title ) {
+ global $wgMemc, $wgEnableFastLinkCache;
if ( array_key_exists( $title, $this->mGoodLinks ) ) {
return $this->mGoodLinks[$title];
- } else {
- return 0;
}
+ if ( $wgEnableFastLinkCache ) {
+ return (int) $wgMemc->get(wfMemcKey("linkcache:good:$title"));
+ }
+ return 0;
}
/**
@@ -53,16 +57,25 @@
* @return mixed
*/
public function getGoodLinkFieldObj( $title, $field ) {
+ global $wgMemc, $wgEnableFastLinkCache;
$dbkey = $title->getPrefixedDbKey();
if ( array_key_exists( $dbkey, $this->mGoodLinkFields ) ) {
return $this->mGoodLinkFields[$dbkey][$field];
- } else {
- return null;
}
+ if ( $wgEnableFastLinkCache ) {
+ $fields = $wgMemc->get(wfMemcKey("linkcache:fields:$dbkey"));
+ return $fields ? $fields[$field] : null;
+ }
+ return null;
}
+ /* boolean isBadLink
+ * @param String title
+ */
public function isBadLink( $title ) {
- return array_key_exists( $title, $this->mBadLinks );
+ global $wgMemc, $wgEnableFastLinkCache;
+ if ( array_key_exists( $title, $this->mBadLinks ) ) return true;
+ return false;
}
/**
@@ -73,14 +86,21 @@
* @param int $redir
*/
public function addGoodLinkObj( $id, $title, $len = -1, $redir = null ) {
+ global $wgMemc, $wgEnableFastLinkCache;
$dbkey = $title->getPrefixedDbKey();
$this->mGoodLinks[$dbkey] = intval( $id );
- $this->mGoodLinkFields[$dbkey] = array(
+ $fields = array(
'length' => intval( $len ),
'redirect' => intval( $redir ) );
+ $this->mGoodLinkFields[$dbkey] = $fields;
+ if ( $wgEnableFastLinkCache ) {
+ $wgMemc->set(wfMemcKey("linkcache:good:$dbkey"), intval( $id ), 3600);
+ $wgMemc->set(wfMemcKey("linkcache:fields:$dbkey"), $fields, 3600);
+ }
}
public function addBadLinkObj( $title ) {
+ global $wgMemc, $wgEnableFastLinkCache;
$dbkey = $title->getPrefixedDbKey();
if ( !$this->isBadLink( $dbkey ) ) {
$this->mBadLinks[$dbkey] = 1;
@@ -88,10 +108,12 @@
}
public function clearBadLink( $title ) {
+ global $wgMemc, $wgEnableFastLinkCache;
unset( $this->mBadLinks[$title] );
}
public function clearLink( $title ) {
+ global $wgMemc, $wgEnableFastLinkCache;
$dbkey = $title->getPrefixedDbKey();
if( isset($this->mBadLinks[$dbkey]) ) {
unset($this->mBadLinks[$dbkey]);
@@ -102,8 +124,13 @@
if( isset($this->mGoodLinkFields[$dbkey]) ) {
unset($this->mGoodLinkFields[$dbkey]);
}
+ if ( $wgEnableFastLinkCache ) {
+ $wgMemc->delete(wfMemcKey("linkcache:good:$dbkey"));
+ $wgMemc->delete(wfMemcKey("linkcache:fields:$dbkey"));
+ }
}
+ // These are deliberately not in memcache
public function getGoodLinks() { return $this->mGoodLinks; }
public function getBadLinks() { return array_keys( $this->mBadLinks ); }