$searchResult = $id;
// As store returned an ID we know we inserted so delete from WAN cache
- $this->purgeWANCache(
- function () {
- $this->cache->delete( $this->getCacheKey() );
- }
- );
+ $dbw = $this->getDBConnection( DB_MASTER );
+ $dbw->onTransactionPreCommitOrIdle( function () {
+ $this->cache->delete( $this->getCacheKey() );
+ } );
}
$this->tableCache = $table;
}
* @return string[] The freshly reloaded name map
*/
public function reloadMap( $connFlags = 0 ) {
- $this->tableCache = $this->loadTable(
- $this->getDBConnection( DB_MASTER, $connFlags )
- );
- $this->purgeWANCache(
- function () {
- $this->cache->reap( $this->getCacheKey(), INF );
- }
- );
+ $dbw = $this->getDBConnection( DB_MASTER, $connFlags );
+ $this->tableCache = $this->loadTable( $dbw );
+ $dbw->onTransactionPreCommitOrIdle( function () {
+ $this->cache->reap( $this->getCacheKey(), INF );
+ } );
return $this->tableCache;
}
return $table;
}
- /**
- * Reap the WANCache entry for this table.
- *
- * @param callable $purgeCallback Callback to 'purge' the WAN cache
- */
- private function purgeWANCache( $purgeCallback ) {
- // If the LB has no DB changes don't bother with onTransactionPreCommitOrIdle
- if ( !$this->loadBalancer->hasOrMadeRecentMasterChanges() ) {
- $purgeCallback();
- return;
- }
-
- $this->getDBConnection( DB_MASTER )
- ->onTransactionPreCommitOrIdle( $purgeCallback, __METHOD__ );
- }
-
/**
* Gets the table from the db
*
if ( $success ) {
$this->mTouched = $newTouched;
- $this->clearSharedCache();
+ $this->clearSharedCache( 'changed' );
} else {
// Clears on failure too since that is desired if the cache is stale
$this->clearSharedCache( 'refresh' );
*
* Called implicitly from invalidateCache() and saveSettings().
*
- * @param string $mode Use 'refresh' to clear now; otherwise before DB commit
+ * @param string $mode Use 'refresh' to clear now or 'changed' to clear before DB commit
*/
- public function clearSharedCache( $mode = 'changed' ) {
+ public function clearSharedCache( $mode = 'refresh' ) {
if ( !$this->getId() ) {
return;
}
+ $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$key = $this->getCacheKey( $cache );
+
if ( $mode === 'refresh' ) {
- $cache->delete( $key, 1 );
+ $cache->delete( $key, 1 ); // low tombstone/"hold-off" TTL
} else {
- $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
- if ( $lb->hasOrMadeRecentMasterChanges() ) {
- $lb->getConnection( DB_MASTER )->onTransactionPreCommitOrIdle(
- function () use ( $cache, $key ) {
- $cache->delete( $key );
- },
- __METHOD__
- );
- } else {
- $cache->delete( $key );
- }
+ $lb->getConnection( DB_MASTER )->onTransactionPreCommitOrIdle(
+ function () use ( $cache, $key ) {
+ $cache->delete( $key );
+ },
+ __METHOD__
+ );
}
}
*/
public function invalidateCache() {
$this->touch();
- $this->clearSharedCache();
+ $this->clearSharedCache( 'changed' );
}
/**
$this->saveOptions();
Hooks::run( 'UserSaveSettings', [ $this ] );
- $this->clearSharedCache();
+ $this->clearSharedCache( 'changed' );
$this->getUserPage()->purgeSquid();
}