Remove ObjectCache dependency from MultiWriteBagOStuff
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 9 Oct 2015 07:15:47 +0000 (00:15 -0700)
committerKrinkle <krinklemail@gmail.com>
Tue, 20 Oct 2015 00:16:51 +0000 (00:16 +0000)
This brings it closer to being able to move to /libs.

Change-Id: Ia733f9023e56d4a25ffcb99ca0cc8b29cbb2ad45

includes/libs/objectcache/ReplicatedBagOStuff.php
includes/objectcache/MultiWriteBagOStuff.php

index 9812047..b98c982 100644 (file)
@@ -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
index c05ecb6..a9304c1 100644 (file)
@@ -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';