Convert ChangesList from MapCacheLRU to HashBagOStuff
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 3 Nov 2015 06:39:09 +0000 (06:39 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 4 Nov 2015 01:44:47 +0000 (01:44 +0000)
Also make use of getWithSetCallback() while at it.

Change-Id: I6bd29db7c6564fcaf4489ec0f226ac83bafc75e8

includes/changes/ChangesList.php

index 9ac6c32..2494ef1 100644 (file)
@@ -36,8 +36,8 @@ class ChangesList extends ContextSource {
        protected $rclistOpen;
        protected $rcMoveIndex;
 
-       /** @var MapCacheLRU */
-       protected $watchingCache;
+       /** @var BagOStuff */
+       protected $watchMsgCache;
 
        /**
         * Changeslist constructor
@@ -53,7 +53,7 @@ class ChangesList extends ContextSource {
                        $this->skin = $obj;
                }
                $this->preCacheMessages();
-               $this->watchingCache = new MapCacheLRU( 50 );
+               $this->watchMsgCache = new HashBagOStuff( array( 'maxKeys' => 50 ) );
        }
 
        /**
@@ -500,17 +500,17 @@ class ChangesList extends ContextSource {
         * @return string
         */
        protected function numberofWatchingusers( $count ) {
-               $cache = $this->watchingCache;
-               if ( $count > 0 ) {
-                       if ( !$cache->has( $count ) ) {
-                               $cache->set( $count, $this->msg( 'number_of_watching_users_RCview' )
-                                       ->numParams( $count )->escaped() );
-                       }
-
-                       return $cache->get( $count );
-               } else {
+               if ( $count <= 0 ) {
                        return '';
                }
+               $cache = $this->watchMsgCache;
+               $that = $this;
+               return $cache->getWithSetCallback( $count, $cache::TTL_INDEFINITE,
+                       function () use ( $that, $count ) {
+                               return $that->msg( 'number_of_watching_users_RCview' )
+                                       ->numParams( $count )->escaped();
+                       }
+               );
        }
 
        /**