Merge "Unpersist the session on logout"
[lhc/web/wiklou.git] / includes / user / User.php
index 1f9e882..7bc410d 100644 (file)
@@ -187,6 +187,12 @@ class User implements IDBAccessObject {
         */
        protected static $mAllRights = false;
 
+       /**
+        * An in-process cache for user data lookup
+        * @var HashBagOStuff
+        */
+       protected static $inProcessCache;
+
        /** Cache variables */
        // @{
        public $mId;
@@ -443,7 +449,10 @@ class User implements IDBAccessObject {
         */
        public static function purge( $wikiId, $userId ) {
                $cache = ObjectCache::getMainWANInstance();
-               $cache->delete( $cache->makeGlobalKey( 'user', 'id', $wikiId, $userId ) );
+               $processCache = self::getInProcessCache();
+               $key = $cache->makeGlobalKey( 'user', 'id', $wikiId, $userId );
+               $cache->delete( $key );
+               $processCache->delete( $key );
        }
 
        /**
@@ -455,6 +464,17 @@ class User implements IDBAccessObject {
                return $cache->makeGlobalKey( 'user', 'id', wfWikiID(), $this->mId );
        }
 
+       /**
+        * @since 1.27
+        * @return HashBagOStuff
+        */
+       protected static function getInProcessCache() {
+               if ( !self::$inProcessCache ) {
+                       self::$inProcessCache = new HashBagOStuff( ['maxKeys' => 10] );
+               }
+               return self::$inProcessCache;
+       }
+
        /**
         * Load user data from shared cache, given mId has already been set.
         *
@@ -468,9 +488,8 @@ class User implements IDBAccessObject {
                }
 
                $cache = ObjectCache::getMainWANInstance();
+               $processCache = self::getInProcessCache();
                $key = $this->getCacheKey( $cache );
-
-               $processCache = ObjectCache::getLocalServerInstance( 'hash' );
                $data = $processCache->get( $key );
                if ( !is_array( $data ) ) {
                        $data = $cache->get( $key );
@@ -513,8 +532,10 @@ class User implements IDBAccessObject {
                $opts = Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
 
                $cache = ObjectCache::getMainWANInstance();
+               $processCache = self::getInProcessCache();
                $key = $this->getCacheKey( $cache );
                $cache->set( $key, $data, $cache::TTL_HOUR, $opts );
+               $processCache->set( $key, $data );
        }
 
        /** @name newFrom*() static factory methods */
@@ -2302,13 +2323,18 @@ class User implements IDBAccessObject {
                }
 
                $cache = ObjectCache::getMainWANInstance();
+               $processCache = self::getInProcessCache();
                $key = $this->getCacheKey( $cache );
                if ( $mode === 'refresh' ) {
                        $cache->delete( $key, 1 );
+                       $processCache->delete( $key );
                } else {
-                       wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() use ( $cache, $key ) {
-                               $cache->delete( $key );
-                       } );
+                       wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle(
+                               function() use ( $cache, $processCache, $key ) {
+                                       $cache->delete( $key );
+                                       $processCache->delete( $key );
+                               }
+                       );
                }
        }