Bound the cache size of numberofWatchingusers()
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 20 Aug 2014 23:58:13 +0000 (16:58 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Sep 2014 19:49:43 +0000 (12:49 -0700)
Change-Id: I60c9898318e340ee3c97d24b528d85a5f8c492e5

includes/changes/ChangesList.php

index 9b9c102..536c6ab 100644 (file)
@@ -36,6 +36,9 @@ class ChangesList extends ContextSource {
        protected $rclistOpen;
        protected $rcMoveIndex;
 
+       /** @var MapCacheLRU */
+       protected $watchingCache;
+
        /**
         * Changeslist constructor
         *
@@ -50,6 +53,7 @@ class ChangesList extends ContextSource {
                        $this->skin = $obj;
                }
                $this->preCacheMessages();
+               $this->watchingCache = new MapCacheLRU( 50 );
        }
 
        /**
@@ -460,14 +464,14 @@ class ChangesList extends ContextSource {
         * @return string
         */
        protected function numberofWatchingusers( $count ) {
-               static $cache = array();
+               $cache = $this->watchingCache;
                if ( $count > 0 ) {
-                       if ( !isset( $cache[$count] ) ) {
-                               $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )
-                                       ->numParams( $count )->escaped();
+                       if ( !$cache->has( $count ) ) {
+                               $cache->set( $count, $this->msg( 'number_of_watching_users_RCview' )
+                                       ->numParams( $count )->escaped() );
                        }
 
-                       return $cache[$count];
+                       return $cache->get( $count );
                } else {
                        return '';
                }