objectcache: Implement 'fallback' param for newAccelerator()
[lhc/web/wiklou.git] / includes / objectcache / ObjectCache.php
index 069cd95..0d40052 100644 (file)
@@ -59,10 +59,11 @@ use MediaWiki\Logger\LoggerFactory;
  *   Delete events are broadcasted to other DCs. See WANObjectCache for details.
  *
  * - ObjectCache::getMainStashInstance()
- *   Purpose: Storage.
+ *   Purpose: Ephemeral storage.
  *   Stored centrally within the local data-center.
  *   Changes are replicated to other DCs (eventually consistent).
  *   To retrieve the latest value (e.g. not from a slave), use BagOStuff:READ_LATEST.
+ *   This store may be subject to LRU style evictions.
  *
  * - wfGetCache( $cacheType )
  *   Get a specific cache type by key in $wgObjectCaches.
@@ -184,14 +185,24 @@ class ObjectCache {
         * This will look for any APC style server-local cache.
         * A fallback cache can be specified if none is found.
         *
-        * @param array $params [optional]
+        *     // Direct calls
+        *     ObjectCache::newAccelerator( $fallbackType );
+        *
+        *     // From $wgObjectCaches via newFromParams()
+        *     ObjectCache::newAccelerator( array( 'fallback' => $fallbackType ) );
+        *
+        * @param array $params [optional] Array key 'fallback' for $fallback.
         * @param int|string $fallback Fallback cache, e.g. (CACHE_NONE, "hash") (since 1.24)
         * @return BagOStuff
         * @throws MWException
         */
        public static function newAccelerator( $params = array(), $fallback = null ) {
-               if ( !is_array( $params ) && $fallback === null ) {
-                       $fallback = $params;
+               if ( $fallback === null ) {
+                       if ( isset( $params['fallback'] ) ) {
+                               $fallback = $params['fallback'];
+                       } elseif ( !is_array( $params ) ) {
+                               $fallback = $params;
+                       }
                }
                if ( function_exists( 'apc_fetch' ) ) {
                        $id = 'apc';