X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Finterwiki%2FInterwiki.php;h=7a49f9be89b7f45c437de036e59cb8caceb5b467;hb=c1f49bc7ce0c72ccaf0de6ad1f86c6c955766eca;hp=02fbb0802b1f3a90033b30e7602c50f4f1ab7f9a;hpb=8c3738e088f377642c540a0ccddb01b16ba7116b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/interwiki/Interwiki.php b/includes/interwiki/Interwiki.php index 02fbb0802b..7a49f9be89 100644 --- a/includes/interwiki/Interwiki.php +++ b/includes/interwiki/Interwiki.php @@ -114,6 +114,17 @@ class Interwiki { return $iw; } + /** + * Purge the cache for an interwiki prefix + * @param string $prefix + * @since 1.26 + */ + public static function invalidateCache( $prefix ) { + $cache = ObjectCache::getMainWANInstance(); + $key = wfMemcKey( 'interwiki', $prefix ); + $cache->delete( $key ); + } + /** * Fetch interwiki prefix data from local cache in constant database. * @@ -191,54 +202,42 @@ class Interwiki { * @return Interwiki|bool Interwiki if $prefix is valid, otherwise false */ protected static function load( $prefix ) { - global $wgMemc, $wgInterwikiExpiry; + global $wgInterwikiExpiry; $iwData = array(); if ( !Hooks::run( 'InterwikiLoadPrefix', array( $prefix, &$iwData ) ) ) { return Interwiki::loadFromArray( $iwData ); } - if ( !$iwData ) { - $key = wfMemcKey( 'interwiki', $prefix ); - $iwData = $wgMemc->get( $key ); - if ( $iwData === '!NONEXISTENT' ) { - // negative cache hit - return false; - } - } - - // is_array is hack for old keys - if ( $iwData && is_array( $iwData ) ) { + if ( is_array( $iwData ) ) { $iw = Interwiki::loadFromArray( $iwData ); if ( $iw ) { - return $iw; + return $iw; // handled by hook } } - $db = wfGetDB( DB_SLAVE ); + $iwData = ObjectCache::getMainWANInstance()->getWithSetCallback( + wfMemcKey( 'interwiki', $prefix ), + function ( $oldValue, &$ttl, array &$setOpts ) use ( $prefix ) { + $dbr = wfGetDB( DB_SLAVE ); - $row = $db->fetchRow( $db->select( - 'interwiki', - self::selectFields(), - array( 'iw_prefix' => $prefix ), - __METHOD__ - ) ); - - $iw = Interwiki::loadFromArray( $row ); - if ( $iw ) { - $mc = array( - 'iw_url' => $iw->mURL, - 'iw_api' => $iw->mAPI, - 'iw_local' => $iw->mLocal, - 'iw_trans' => $iw->mTrans - ); - $wgMemc->add( $key, $mc, $wgInterwikiExpiry ); + $setOpts += Database::getCacheSetOptions( $dbr ); - return $iw; - } + $row = $dbr->selectRow( + 'interwiki', + Interwiki::selectFields(), + array( 'iw_prefix' => $prefix ), + __METHOD__ + ); - // negative cache hit - $wgMemc->add( $key, '!NONEXISTENT', $wgInterwikiExpiry ); + return $row ? (array)$row : '!NONEXISTENT'; + }, + $wgInterwikiExpiry + ); + + if ( is_array( $iwData ) ) { + return Interwiki::loadFromArray( $iwData ) ?: false; + } return false; }