X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FUser.php;h=b09e4e456e8b3a1c46cd9bc1026029baf4b36a28;hb=b3acd4fb5d1263de5735c714a11f7a170777d1f1;hp=eb3ab9d2a2cd240be26d5156a138d11fe7fafae6;hpb=87a998f4821f154bb463e76f3c93248cd4365500;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/User.php b/includes/User.php index eb3ab9d2a2..b09e4e456e 100644 --- a/includes/User.php +++ b/includes/User.php @@ -387,6 +387,25 @@ class User implements IDBAccessObject { return true; } + /** + * @since 1.27 + * @param string $wikiId + * @param integer $userId + */ + public static function purge( $wikiId, $userId ) { + $cache = ObjectCache::getMainWANInstance(); + $cache->delete( $cache->makeGlobalKey( 'user', 'id', $wikiId, $userId ) ); + } + + /** + * @since 1.27 + * @param WANObjectCache $cache + * @return string + */ + protected function getCacheKey( WANObjectCache $cache ) { + return $cache->makeGlobalKey( 'user', 'id', wfWikiID(), $this->mId ); + } + /** * Load user data from shared cache, given mId has already been set. * @@ -399,8 +418,8 @@ class User implements IDBAccessObject { return false; } - $key = wfMemcKey( 'user', 'id', $this->mId ); - $data = ObjectCache::getMainWANInstance()->get( $key ); + $cache = ObjectCache::getMainWANInstance(); + $data = $cache->get( $this->getCacheKey( $cache ) ); if ( !is_array( $data ) || $data['mVersion'] < self::VERSION ) { // Object is expired return false; @@ -439,7 +458,7 @@ class User implements IDBAccessObject { $opts = Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); $cache = ObjectCache::getMainWANInstance(); - $key = wfMemcKey( 'user', 'id', $this->mId ); + $key = $this->getCacheKey( $cache ); $cache->set( $key, $data, $cache::TTL_HOUR, $opts ); } @@ -2228,17 +2247,17 @@ class User implements IDBAccessObject { * @param string $mode Use 'refresh' to clear now; otherwise before DB commit */ public function clearSharedCache( $mode = 'changed' ) { - $id = $this->getId(); - if ( !$id ) { + if ( !$this->getId() ) { return; } - $key = wfMemcKey( 'user', 'id', $id ); + $cache = ObjectCache::getMainWANInstance(); + $key = $this->getCacheKey( $cache ); if ( $mode === 'refresh' ) { - ObjectCache::getMainWANInstance()->delete( $key, 1 ); + $cache->delete( $key, 1 ); } else { - wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() use ( $key ) { - ObjectCache::getMainWANInstance()->delete( $key ); + wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() use ( $cache, $key ) { + $cache->delete( $key ); } ); } }