*/
protected static $mAllRights = false;
+ /**
+ * An in-process cache for user data lookup
+ * @var HashBagOStuff
+ */
+ protected static $inProcessCache;
+
/** Cache variables */
// @{
public $mId;
*/
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 );
}
/**
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.
*
}
$cache = ObjectCache::getMainWANInstance();
- $data = $cache->get( $this->getCacheKey( $cache ) );
- if ( !is_array( $data ) || $data['mVersion'] < self::VERSION ) {
- // Object is expired
- return false;
+ $processCache = self::getInProcessCache();
+ $key = $this->getCacheKey( $cache );
+ $data = $processCache->get( $key );
+ if ( !is_array( $data ) ) {
+ $data = $cache->get( $key );
+ if ( !is_array( $data ) || $data['mVersion'] < self::VERSION ) {
+ // Object is expired
+ return false;
+ }
+ $processCache->set( $key, $data );
}
-
wfDebug( "User: got user {$this->mId} from cache\n" );
// Restore from cache
$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 */
}
$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 );
+ }
+ );
}
}