*
* The format is an associative array where the key is a cache identifier, and
* the value is an associative array of parameters. The "cacheId" parameter is
- * a cache identifier from $wgObjectCaches. The "relayerConfig" parameter is an
- * array used to construct an EventRelayer object. The "pool" parameter is a
- * string that is used as a PubSub channel prefix. The "loggroup" parameter
- * controls where log events are sent.
+ * a cache identifier from $wgObjectCaches. The "channels" parameter is a map of
+ * actions ('purge') to PubSub channels defined in $wgEventRelayerConfig.
+ * The "loggroup" parameter controls where log events are sent.
*
* @since 1.26
*/
$wgWANObjectCaches = [
CACHE_NONE => [
- 'class' => 'WANObjectCache',
- 'cacheId' => CACHE_NONE,
- 'pool' => 'mediawiki-main-none',
- 'relayerConfig' => [ 'class' => 'EventRelayerNull' ]
+ 'class' => 'WANObjectCache',
+ 'cacheId' => CACHE_NONE,
+ 'channels' => []
]
/* Example of a simple single data-center cache:
- 'memcached-php' => array(
- 'class' => 'WANObjectCache',
- 'cacheId' => 'memcached-php',
- 'pool' => 'mediawiki-main-memcached',
- 'relayerConfig' => array( 'class' => 'EventRelayerNull' )
- )
+ 'memcached-php' => [
+ 'class' => 'WANObjectCache',
+ 'cacheId' => 'memcached-php',
+ 'channels' => [ 'purge' => 'wancache-main-memcached-purge' ]
+ ]
*/
];
// Sites using multiple datacenters can configure a relayer.
$wgMainWANCache = 'mediawiki-main-default';
$wgWANObjectCaches[$wgMainWANCache] = [
- 'class' => 'WANObjectCache',
- 'cacheId' => $wgMainCacheType,
- 'pool' => 'mediawiki-main-default',
- 'relayerConfig' => [ 'class' => 'EventRelayerNull' ]
+ 'class' => 'WANObjectCache',
+ 'cacheId' => $wgMainCacheType,
+ 'channels' => [ 'purge' => 'wancache-main-default-purge' ]
];
}
return $this->doNotify( $channel, $events );
}
- /**
- * Set logger instance.
- * @param LoggerInterface $logger
- */
public function setLogger( LoggerInterface $logger ) {
$this->logger = $logger;
}
protected $cache;
/** @var HashBagOStuff Script instance PHP cache */
protected $procCache;
- /** @var string Cache pool name */
- protected $pool;
+ /** @var string Purge channel name */
+ protected $purgeChannel;
/** @var EventRelayer Bus that handles purge broadcasts */
- protected $relayer;
+ protected $purgeRelayer;
/** @var LoggerInterface */
protected $logger;
const MAX_PC_KEYS = 1000; // max keys to keep in process cache
+ const DEFAULT_PURGE_CHANNEL = 'wancache-purge';
+
/**
* @param array $params
- * - cache : BagOStuff object
- * - pool : pool name
- * - relayer : EventRelayer object
- * - logger : LoggerInterface object
+ * - cache : BagOStuff object for a persistent cache
+ * - channels : Map of (action => channel string). Actions include "purge".
+ * - relayers : Map of (action => EventRelayer object). Actions include "purge".
+ * - logger : LoggerInterface object
*/
public function __construct( array $params ) {
$this->cache = $params['cache'];
- $this->pool = $params['pool'];
- $this->relayer = $params['relayer'];
$this->procCache = new HashBagOStuff( [ 'maxKeys' => self::MAX_PC_KEYS ] );
+ $this->purgeChannel = isset( $params['channels']['purge'] )
+ ? $params['channels']['purge']
+ : self::DEFAULT_PURGE_CHANNEL;
+ $this->purgeRelayer = isset( $params['relayers']['purge'] )
+ ? $params['relayers']['purge']
+ : new EventRelayerNull( [] );
$this->setLogger( isset( $params['logger'] ) ? $params['logger'] : new NullLogger() );
}
- /**
- * Set logger instance.
- * @param LoggerInterface $logger
- */
public function setLogger( LoggerInterface $logger ) {
$this->logger = $logger;
}
'sbt' => true, // substitute $UNIXTIME$ with actual microtime
] );
- $ok = $this->relayer->notify( "{$this->pool}:purge", $event );
+ $ok = $this->purgeRelayer->notify( $this->purgeChannel, $event );
if ( !$ok ) {
$this->lastRelayError = self::ERR_RELAY;
}
'key' => $key,
] );
- $ok = $this->relayer->notify( "{$this->pool}:purge", $event );
+ $ok = $this->purgeRelayer->notify( $this->purgeChannel, $event );
if ( !$ok ) {
$this->lastRelayError = self::ERR_RELAY;
}
}
$params = $wgWANObjectCaches[$id];
- $class = $params['relayerConfig']['class'];
- $params['relayer'] = new $class( $params['relayerConfig'] );
+ foreach ( $params['channels'] as $action => $channel ) {
+ $params['relayers'][$action] = EventRelayerGroup::singleton()->getRelayer( $channel );
+ $params['channels'][$action] = $channel;
+ }
$params['cache'] = self::newFromId( $params['cacheId'] );
if ( isset( $params['loggroup'] ) ) {
$params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );