Let BagOStuff::merge() callbacks override the TTL
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 11 May 2016 20:50:33 +0000 (13:50 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 11 May 2016 20:50:33 +0000 (13:50 -0700)
This is useful if the TTL depends on what is in cache now.

Change-Id: Idde6eb9e156f9ae847f9bc7e3b1f3f511f39ffe4

includes/libs/objectcache/BagOStuff.php

index bf46ce1..dd22d91 100644 (file)
@@ -252,10 +252,12 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
        abstract public function delete( $key );
 
        /**
-        * Merge changes into the existing cache value (possibly creating a new one).
+        * Merge changes into the existing cache value (possibly creating a new one)
+        *
         * The callback function returns the new value given the current value
         * (which will be false if not present), and takes the arguments:
-        * (this BagOStuff, cache key, current value).
+        * (this BagOStuff, cache key, current value, TTL).
+        * The TTL parameter is reference set to $exptime. It can be overriden in the callback.
         *
         * @param string $key
         * @param callable $callback Callback method to be executed
@@ -296,7 +298,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
                        }
 
                        // Derive the new value from the old value
-                       $value = call_user_func( $callback, $this, $key, $currentValue );
+                       $value = call_user_func( $callback, $this, $key, $currentValue, $exptime );
 
                        $this->clearLastError();
                        if ( $value === false ) {
@@ -355,7 +357,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
                        $success = false;
                } else {
                        // Derive the new value from the old value
-                       $value = call_user_func( $callback, $this, $key, $currentValue );
+                       $value = call_user_func( $callback, $this, $key, $currentValue, $exptime );
                        if ( $value === false ) {
                                $success = true; // do nothing
                        } else {