/** * Constructor. Parameters are: * * - caches: This should have a numbered array of cache parameter * structures, in the style required by $wgObjectCaches. See * the documentation of $wgObjectCaches for more detail. * * @param array $params * @throws MWException */ public function __construct($params) { if (!isset($params['caches'])) { throw new MWException(__METHOD__ . ': the caches parameter is required'); } $this->caches = array(); foreach ($params['caches'] as $cacheInfo) { $this->caches[] = ObjectCache::newFromParams($cacheInfo); } }
/** * $params include: * - caches: This should have a numbered array of cache parameter * structures, in the style required by $wgObjectCaches. See * the documentation of $wgObjectCaches for more detail. * BagOStuff objects can also be used as values. * The first cache is the primary one, being the first to * be read in the fallback chain. Writes happen to all stores * in the order they are defined. However, lock()/unlock() calls * only use the primary store. * - replication: Either 'sync' or 'async'. This controls whether writes to * secondary stores are deferred when possible. Async writes * require the HHVM register_postsend_function() function. * Async writes can increase the chance of some race conditions * or cause keys to expire seconds later than expected. It is * safe to use for modules when cached values: are immutable, * invalidation uses logical TTLs, invalidation uses etag/timestamp * validation against the DB, or merge() is used to handle races. * * @param array $params * @throws InvalidArgumentException */ public function __construct($params) { parent::__construct($params); if (empty($params['caches']) || !is_array($params['caches'])) { throw new InvalidArgumentException(__METHOD__ . ': "caches" parameter must be an array of caches'); } $this->caches = array(); foreach ($params['caches'] as $cacheInfo) { $this->caches[] = $cacheInfo instanceof BagOStuff ? $cacheInfo : ObjectCache::newFromParams($cacheInfo); } $this->asyncWrites = isset($params['replication']) && $params['replication'] === 'async'; }
/** * Construct a new instance from configuration. * * @param array $config Parameters include: * - lockServers : Associative array of server names to "<IP>:<port>" strings. * - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0, * each having an odd-numbered list of server names (peers) as values. * - memcConfig : Configuration array for ObjectCache::newFromParams. [optional] * If set, this must use one of the memcached classes. * @throws Exception */ public function __construct(array $config) { parent::__construct($config); // Sanitize srvsByBucket config to prevent PHP errors $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array'); $this->srvsByBucket = array_values($this->srvsByBucket); // consecutive $memcConfig = isset($config['memcConfig']) ? $config['memcConfig'] : ['class' => 'MemcachedPhpBagOStuff']; foreach ($config['lockServers'] as $name => $address) { $params = ['servers' => [$address]] + $memcConfig; $cache = ObjectCache::newFromParams($params); if ($cache instanceof MemcachedBagOStuff) { $this->bagOStuffs[$name] = $cache; } else { throw new Exception('Only MemcachedBagOStuff classes are supported by MemcLockManager.'); } } $this->session = wfRandomString(32); }
/** * Construct a new instance from configuration. * * $config paramaters include: * - lockServers : Associative array of server names to "<IP>:<port>" strings. * - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0, * each having an odd-numbered list of server names (peers) as values. * - memcConfig : Configuration array for ObjectCache::newFromParams. [optional] * If set, this must use one of the memcached classes. * - wikiId : Wiki ID string that all resources are relative to. [optional] * * @param Array $config */ public function __construct(array $config) { parent::__construct($config); // Sanitize srvsByBucket config to prevent PHP errors $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array'); $this->srvsByBucket = array_values($this->srvsByBucket); // consecutive $memcConfig = isset($config['memcConfig']) ? $config['memcConfig'] : array('class' => 'MemcachedPhpBagOStuff'); foreach ($config['lockServers'] as $name => $address) { $params = array('servers' => array($address)) + $memcConfig; $cache = ObjectCache::newFromParams($params); if ($cache instanceof MemcachedBagOStuff) { $this->bagOStuffs[$name] = $cache; } else { throw new MWException('Only MemcachedBagOStuff classes are supported by MemcLockManager.'); } } $this->wikiId = isset($config['wikiId']) ? $config['wikiId'] : wfWikiID(); $met = ini_get('max_execution_time'); // this is 0 in CLI mode $this->lockExpiry = $met ? 2 * (int) $met : 2 * 3600; $this->session = wfRandomString(32); }
return \ObjectCache::newWANCacheFromParams($params); }, 'LocalServerObjectCache' => function (MediaWikiServices $services) { $mainConfig = $services->getMainConfig(); if (function_exists('apc_fetch')) { $id = 'apc'; } elseif (function_exists('apcu_fetch')) { $id = 'apcu'; } elseif (function_exists('xcache_get') && wfIniGetBool('xcache.var_size')) { $id = 'xcache'; } elseif (function_exists('wincache_ucache_get')) { $id = 'wincache'; } else { $id = CACHE_NONE; } if (!isset($mainConfig->get('ObjectCaches')[$id])) { throw new UnexpectedValueException("Cache type \"{$id}\" is not present in \$wgObjectCaches."); } return \ObjectCache::newFromParams($mainConfig->get('ObjectCaches')[$id]); }, 'VirtualRESTServiceClient' => function (MediaWikiServices $services) { $config = $services->getMainConfig()->get('VirtualRestConfig'); $vrsClient = new VirtualRESTServiceClient(new MultiHttpClient([])); foreach ($config['paths'] as $prefix => $serviceConfig) { $class = $serviceConfig['class']; // Merge in the global defaults $constructArg = isset($serviceConfig['options']) ? $serviceConfig['options'] : []; $constructArg += $config['global']; // Make the VRS service available at the mount point $vrsClient->mount($prefix, ['class' => $class, 'config' => $constructArg]); } return $vrsClient; }];