use MediaWiki\MediaWikiServices;
/**
- * Handles purging appropriate CDN URLs given a title (or titles)
+ * Handles purging the appropriate CDN objects given a list of URLs or Title instances
* @ingroup Cache
*/
class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
/** @var string[] Collection of URLs to purge */
- protected $urls = [];
+ private $urls = [];
/**
* @param string[] $urlArr Collection of URLs to purge
}
public function merge( MergeableUpdate $update ) {
- /** @var CdnCacheUpdate $update */
+ /** @var self $update */
Assert::parameterType( __CLASS__, $update, '$update' );
+ '@phan-var self $update';
$this->urls = array_merge( $this->urls, $update->urls );
}
}
/**
- * Purges a list of CDN nodes defined in $wgSquidServers.
+ * Purges a list of CDN nodes defined in $wgCdnServers.
* $urlArr should contain the full URLs to purge as values
* (example: $urlArr[] = 'http://my.host/something')
*
* @param string[] $urlArr List of full URLs to purge
*/
public static function purge( array $urlArr ) {
- global $wgSquidServers, $wgHTCPRouting;
+ global $wgCdnServers, $wgHTCPRouting;
if ( !$urlArr ) {
return;
wfDebugLog( 'squid', __METHOD__ . ': ' . implode( ' ', $urlArr ) );
// Reliably broadcast the purge to all edge nodes
- $relayer = MediaWikiServices::getInstance()->getEventRelayerGroup()
- ->getRelayer( 'cdn-url-purges' );
$ts = microtime( true );
- $relayer->notifyMulti(
+ $relayerGroup = MediaWikiServices::getInstance()->getEventRelayerGroup();
+ $relayerGroup->getRelayer( 'cdn-url-purges' )->notifyMulti(
'cdn-url-purges',
array_map(
function ( $url ) use ( $ts ) {
}
// Do direct server purges if enabled (this does not scale very well)
- if ( $wgSquidServers ) {
- // Maximum number of parallel connections per squid
- $maxSocketsPerSquid = 8;
+ if ( $wgCdnServers ) {
+ // Maximum number of parallel connections per CDN
+ $maxSocketsPerCdn = 8;
// Number of requests to send per socket
// 400 seems to be a good tradeoff, opening a socket takes a while
$urlsPerSocket = 400;
- $socketsPerSquid = ceil( count( $urlArr ) / $urlsPerSocket );
- if ( $socketsPerSquid > $maxSocketsPerSquid ) {
- $socketsPerSquid = $maxSocketsPerSquid;
+ $socketsPerCdn = ceil( count( $urlArr ) / $urlsPerSocket );
+ if ( $socketsPerCdn > $maxSocketsPerCdn ) {
+ $socketsPerCdn = $maxSocketsPerCdn;
}
$pool = new SquidPurgeClientPool;
- $chunks = array_chunk( $urlArr, ceil( count( $urlArr ) / $socketsPerSquid ) );
- foreach ( $wgSquidServers as $server ) {
+ $chunks = array_chunk( $urlArr, ceil( count( $urlArr ) / $socketsPerCdn ) );
+ foreach ( $wgCdnServers as $server ) {
foreach ( $chunks as $chunk ) {
$client = new SquidPurgeClient( $server );
foreach ( $chunk as $url ) {
- $client->queuePurge( $url );
+ $client->queuePurge( self::expand( $url ) );
}
$pool->addClient( $client );
}
* @param string $url
* @return string
*/
- public static function expand( $url ) {
+ private static function expand( $url ) {
return wfExpandUrl( $url, PROTO_INTERNAL );
}