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.
*
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;
$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 );
}
* @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 );
} );
}
}
array( 'user_id' => $this->id ),
__METHOD__ );
- $key = wfForeignMemcKey( $this->database, false, 'user', 'id', $this->id );
- $this->db->onTransactionPreCommitOrIdle( function() use ( $key ) {
- ObjectCache::getMainWANInstance()->delete( $key );
+ $wikiId = $this->db->getWikiID();
+ $userId = $this->id;
+ $this->db->onTransactionPreCommitOrIdle( function() use ( $wikiId, $userId ) {
+ User::purge( $wikiId, $userId );
} );
}
}