objectcache: fix failing tests for non-HashBagOStuff backends
[lhc/web/wiklou.git] / includes / libs / objectcache / BagOStuff.php
index 906e955..da60c01 100644 (file)
@@ -115,7 +115,8 @@ abstract class BagOStuff implements IExpiringStore, IStoreKeyEncoder, LoggerAwar
        /**
         * Get an item with the given key, regenerating and setting it if not found
         *
-        * Nothing is stored nor deleted if the callback returns false
+        * The callback can take $ttl as argument by reference and modify it.
+        * Nothing is stored nor deleted if the callback returns false.
         *
         * @param string $key
         * @param int $ttl Time-to-live (seconds)
@@ -128,11 +129,8 @@ abstract class BagOStuff implements IExpiringStore, IStoreKeyEncoder, LoggerAwar
                $value = $this->get( $key, $flags );
 
                if ( $value === false ) {
-                       if ( !is_callable( $callback ) ) {
-                               throw new InvalidArgumentException( "Invalid cache miss callback provided." );
-                       }
-                       $value = call_user_func( $callback );
-                       if ( $value !== false ) {
+                       $value = $callback( $ttl );
+                       if ( $value !== false && $ttl >= 0 ) {
                                $this->set( $key, $value, $ttl, $flags );
                        }
                }
@@ -440,20 +438,20 @@ abstract class BagOStuff implements IExpiringStore, IStoreKeyEncoder, LoggerAwar
         *
         * @since 1.27
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         */
-       abstract public function makeGlobalKey( $class, $component = null );
+       abstract public function makeGlobalKey( $class, ...$components );
 
        /**
         * Make a cache key, scoped to this instance's keyspace.
         *
         * @since 1.27
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         */
-       abstract public function makeKey( $class, $component = null );
+       abstract public function makeKey( $class, ...$components );
 
        /**
         * @param int $flag ATTR_* class constant