From 922f15e8e04a73a22ccd4617b4cb6ebe27132613 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 9 Oct 2015 00:15:47 -0700 Subject: [PATCH] Remove ObjectCache dependency from MultiWriteBagOStuff This brings it closer to being able to move to /libs. Change-Id: Ia733f9023e56d4a25ffcb99ca0cc8b29cbb2ad45 --- .../libs/objectcache/ReplicatedBagOStuff.php | 4 ++-- includes/objectcache/MultiWriteBagOStuff.php | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/includes/libs/objectcache/ReplicatedBagOStuff.php b/includes/libs/objectcache/ReplicatedBagOStuff.php index 98120477d3..b98c982e6f 100644 --- a/includes/libs/objectcache/ReplicatedBagOStuff.php +++ b/includes/libs/objectcache/ReplicatedBagOStuff.php @@ -39,9 +39,9 @@ class ReplicatedBagOStuff extends BagOStuff { /** * Constructor. Parameters are: - * - writeFactory : ObjectFactory::getObjectFromSpec parameters yeilding BagOStuff. + * - writeFactory : ObjectFactory::getObjectFromSpec array yeilding BagOStuff. * This object will be used for writes (e.g. the master DB). - * - readFactory : ObjectFactory::getObjectFromSpec parameters yeilding BagOStuff. + * - readFactory : ObjectFactory::getObjectFromSpec array yeilding BagOStuff. * This object will be used for reads (e.g. a slave DB). * * @param array $params diff --git a/includes/objectcache/MultiWriteBagOStuff.php b/includes/objectcache/MultiWriteBagOStuff.php index c05ecb6d79..a9304c1d9a 100644 --- a/includes/objectcache/MultiWriteBagOStuff.php +++ b/includes/objectcache/MultiWriteBagOStuff.php @@ -41,10 +41,9 @@ class MultiWriteBagOStuff extends BagOStuff { /** * $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. + * - caches: A numbered array of either ObjectFactory::getObjectFromSpec + * arrays yeilding BagOStuff objects or direct BagOStuff objects. + * If using the former, the 'args' field *must* be set. * 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 @@ -72,9 +71,18 @@ class MultiWriteBagOStuff extends BagOStuff { $this->caches = array(); foreach ( $params['caches'] as $cacheInfo ) { - $this->caches[] = ( $cacheInfo instanceof BagOStuff ) - ? $cacheInfo - : ObjectCache::newFromParams( $cacheInfo ); + if ( $cacheInfo instanceof BagOStuff ) { + $this->caches[] = $cacheInfo; + } else { + if ( !isset( $cacheInfo['args'] ) ) { + // B/C for when $cacheInfo was for ObjectCache::newFromParams(). + // Callers intenting this to be for ObjectFactory::getObjectFromSpec + // should have set "args" per the docs above. Doings so avoids extra + // (likely harmless) params (factory/class/calls) ending up in "args". + $cacheInfo['args'] = array( $cacheInfo ); + } + $this->caches[] = ObjectFactory::getObjectFromSpec( $cacheInfo ); + } } $this->asyncWrites = isset( $params['replication'] ) && $params['replication'] === 'async'; -- 2.20.1