Migrate feeds from $messageMemc to the WAN cache
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 10 Nov 2015 06:48:36 +0000 (22:48 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 10 Nov 2015 19:11:05 +0000 (11:11 -0800)
This makes the delete() calls work properly for all DCs.
Also, using the message cache was fairly bizzare.

Change-Id: Idec7fa47811e982ba89bb8fbbd9565a26585e77f

includes/FeedUtils.php
includes/changes/ChangesFeed.php

index 57ba4b3..b058975 100644 (file)
@@ -30,18 +30,19 @@ class FeedUtils {
 
        /**
         * Check whether feed's cache should be cleared; for changes feeds
-        * If the feed should be purged; $timekey and $key will be removed from
-        * $messageMemc
+        * If the feed should be purged; $timekey and $key will be removed from cache
         *
         * @param string $timekey Cache key of the timestamp of the last item
         * @param string $key Cache key of feed's content
         */
        public static function checkPurge( $timekey, $key ) {
-               global $wgRequest, $wgUser, $messageMemc;
+               global $wgRequest, $wgUser;
+
                $purge = $wgRequest->getVal( 'action' ) === 'purge';
                if ( $purge && $wgUser->isAllowed( 'purge' ) ) {
-                       $messageMemc->delete( $timekey );
-                       $messageMemc->delete( $key );
+                       $cache = ObjectCache::getMainWANInstance();
+                       $cache->delete( $timekey, 1 );
+                       $cache->delete( $key, 1 );
                }
        }
 
index 28a1cca..dc58835 100644 (file)
@@ -83,7 +83,8 @@ class ChangesFeed {
                }
 
                $optionsHash = md5( serialize( $opts->getAllValues() ) ) . $wgRenderHashAppend;
-               $timekey = wfMemcKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash, 'timestamp' );
+               $timekey = wfMemcKey(
+                       $this->type, $this->format, $wgLang->getCode(), $optionsHash, 'timestamp' );
                $key = wfMemcKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash );
 
                FeedUtils::checkPurge( $timekey, $key );
@@ -110,21 +111,20 @@ class ChangesFeed {
        }
 
        /**
-        * Save to feed result to $messageMemc
+        * Save to feed result to cache
         *
         * @param string $feed Feed's content
         * @param string $timekey Memcached key of the last modification
         * @param string $key Memcached key of the content
         */
        public function saveToCache( $feed, $timekey, $key ) {
-               global $messageMemc;
-               $expire = 3600 * 24; # One day
-               $messageMemc->set( $key, $feed, $expire );
-               $messageMemc->set( $timekey, wfTimestamp( TS_MW ), $expire );
+               $cache = ObjectCache::getMainWANInstance();
+               $cache->set( $key, $feed, $cache::TTL_DAY );
+               $cache->set( $timekey, wfTimestamp( TS_MW ), $cache::TTL_DAY );
        }
 
        /**
-        * Try to load the feed result from $messageMemc
+        * Try to load the feed result from cache
         *
         * @param int $lastmod Timestamp of the last item in the recentchanges table
         * @param string $timekey Memcached key of the last modification
@@ -132,9 +132,10 @@ class ChangesFeed {
         * @return string|bool Feed's content on cache hit or false on cache miss
         */
        public function loadFromCache( $lastmod, $timekey, $key ) {
-               global $wgFeedCacheTimeout, $wgOut, $messageMemc;
+               global $wgFeedCacheTimeout, $wgOut;
 
-               $feedLastmod = $messageMemc->get( $timekey );
+               $cache = ObjectCache::getMainWANInstance();
+               $feedLastmod = $cache->get( $timekey );
 
                if ( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) {
                        /**
@@ -153,7 +154,7 @@ class ChangesFeed {
                                if ( $feedLastmodUnix < $lastmodUnix ) {
                                        $wgOut->setLastModified( $feedLastmod ); // bug 21916
                                }
-                               return $messageMemc->get( $key );
+                               return $cache->get( $key );
                        } else {
                                wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
                        }
@@ -164,7 +165,7 @@ class ChangesFeed {
        /**
         * Generate the feed items given a row from the database, printing the feed.
         * @param object $rows DatabaseBase resource with recentchanges rows
-        * @param Feed $feed
+        * @param ChannelFeed $feed
         */
        public static function generateFeed( $rows, &$feed ) {
                $items = self::buildItems( $rows );