objectcache: fix failing tests for non-HashBagOStuff backends
[lhc/web/wiklou.git] / includes / libs / objectcache / BagOStuff.php
index 8c99532..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 );
                        }
                }