From ac5512b48daadd593e69a75732956d7af17a9010 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 11 May 2016 13:50:33 -0700 Subject: [PATCH] Let BagOStuff::merge() callbacks override the TTL This is useful if the TTL depends on what is in cache now. Change-Id: Idde6eb9e156f9ae847f9bc7e3b1f3f511f39ffe4 --- includes/libs/objectcache/BagOStuff.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index bf46ce1648..dd22d9144d 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -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 { -- 2.20.1