Convert LinkCache to using MapCacheLRU
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 11 Jul 2018 13:11:12 +0000 (14:11 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 16 Jul 2018 21:16:00 +0000 (21:16 +0000)
Clean up the variable names while at it.

Change-Id: I3b7860c0657111d73567e247bcc1ebcbaef53e22

includes/cache/LinkCache.php

index 58ed771..260038a 100644 (file)
@@ -32,10 +32,10 @@ use MediaWiki\MediaWikiServices;
  * @ingroup Cache
  */
 class LinkCache {
-       /** @var HashBagOStuff */
-       private $mGoodLinks;
-       /** @var HashBagOStuff */
-       private $mBadLinks;
+       /** @var MapCacheLRU */
+       private $goodLinks;
+       /** @var MapCacheLRU */
+       private $badLinks;
        /** @var WANObjectCache */
        private $wanCache;
 
@@ -52,8 +52,8 @@ class LinkCache {
        const MAX_SIZE = 10000;
 
        public function __construct( TitleFormatter $titleFormatter, WANObjectCache $cache ) {
-               $this->mGoodLinks = new HashBagOStuff( [ 'maxKeys' => self::MAX_SIZE ] );
-               $this->mBadLinks = new HashBagOStuff( [ 'maxKeys' => self::MAX_SIZE ] );
+               $this->goodLinks = new MapCacheLRU( self::MAX_SIZE );
+               $this->badLinks = new MapCacheLRU( self::MAX_SIZE );
                $this->wanCache = $cache;
                $this->titleFormatter = $titleFormatter;
        }
@@ -87,7 +87,7 @@ class LinkCache {
         * @return int Page ID or zero
         */
        public function getGoodLinkID( $title ) {
-               $info = $this->mGoodLinks->get( $title );
+               $info = $this->goodLinks->get( $title );
                if ( !$info ) {
                        return 0;
                }
@@ -103,7 +103,7 @@ class LinkCache {
         */
        public function getGoodLinkFieldObj( LinkTarget $target, $field ) {
                $dbkey = $this->titleFormatter->getPrefixedDBkey( $target );
-               $info = $this->mGoodLinks->get( $dbkey );
+               $info = $this->goodLinks->get( $dbkey );
                if ( !$info ) {
                        return null;
                }
@@ -116,7 +116,7 @@ class LinkCache {
         */
        public function isBadLink( $title ) {
                // Use get() to ensure it records as used for LRU.
-               return $this->mBadLinks->get( $title ) !== false;
+               return $this->badLinks->has( $title );
        }
 
        /**
@@ -134,7 +134,7 @@ class LinkCache {
                $revision = 0, $model = null, $lang = null
        ) {
                $dbkey = $this->titleFormatter->getPrefixedDBkey( $target );
-               $this->mGoodLinks->set( $dbkey, [
+               $this->goodLinks->set( $dbkey, [
                        'id' => (int)$id,
                        'length' => (int)$len,
                        'redirect' => (int)$redir,
@@ -153,7 +153,7 @@ class LinkCache {
         */
        public function addGoodLinkObjFromRow( LinkTarget $target, $row ) {
                $dbkey = $this->titleFormatter->getPrefixedDBkey( $target );
-               $this->mGoodLinks->set( $dbkey, [
+               $this->goodLinks->set( $dbkey, [
                        'id' => intval( $row->page_id ),
                        'length' => intval( $row->page_len ),
                        'redirect' => intval( $row->page_is_redirect ),
@@ -169,7 +169,7 @@ class LinkCache {
        public function addBadLinkObj( LinkTarget $target ) {
                $dbkey = $this->titleFormatter->getPrefixedDBkey( $target );
                if ( !$this->isBadLink( $dbkey ) ) {
-                       $this->mBadLinks->set( $dbkey, 1 );
+                       $this->badLinks->set( $dbkey, 1 );
                }
        }
 
@@ -177,7 +177,7 @@ class LinkCache {
         * @param string $title Prefixed DB key
         */
        public function clearBadLink( $title ) {
-               $this->mBadLinks->delete( $title );
+               $this->badLinks->clear( $title );
        }
 
        /**
@@ -185,8 +185,8 @@ class LinkCache {
         */
        public function clearLink( LinkTarget $target ) {
                $dbkey = $this->titleFormatter->getPrefixedDBkey( $target );
-               $this->mBadLinks->delete( $dbkey );
-               $this->mGoodLinks->delete( $dbkey );
+               $this->badLinks->clear( $dbkey );
+               $this->goodLinks->clear( $dbkey );
        }
 
        /**
@@ -332,7 +332,7 @@ class LinkCache {
         * Clears cache
         */
        public function clear() {
-               $this->mGoodLinks->clear();
-               $this->mBadLinks->clear();
+               $this->goodLinks->clear();
+               $this->badLinks->clear();
        }
 }