X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=blobdiff_plain;f=includes%2Flibs%2Fobjectcache%2FBagOStuff.php;h=5472e837d4c0c67fffba10e943d7c53fce69260d;hb=2e7f4e48735b0e916336d9166cb1ab1756e0fa9f;hp=bf46ce1648908d8a344635475a0a6080c1df9aae;hpb=edcba98e35ca1fd95697fdece32bb3941289f263;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index bf46ce1648..5472e837d4 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -46,7 +46,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { /** @var array[] Lock tracking */ protected $locks = []; - /** @var integer */ + /** @var integer ERR_* class constant */ protected $lastError = self::ERR_NONE; /** @var string */ @@ -70,6 +70,9 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { /** @var bool */ private $dupeTrackScheduled = false; + /** @var integer[] Map of (ATTR_* class constant => QOS_* class constant) */ + protected $attrMap = []; + /** Possible values for getLastError() */ const ERR_NONE = 0; // no error const ERR_NO_RESPONSE = 1; // no response @@ -252,10 +255,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 @@ -265,11 +270,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * @return bool Success * @throws InvalidArgumentException */ - public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { - if ( !is_callable( $callback ) ) { - throw new InvalidArgumentException( "Got invalid callback." ); - } - + public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { return $this->mergeViaLock( $key, $callback, $exptime, $attempts, $flags ); } @@ -296,7 +297,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 +356,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 { @@ -371,6 +372,20 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { return $success; } + /** + * Reset the TTL on a key if it exists + * + * @param string $key + * @param int $expiry + * @return bool Success Returns false if there is no key + * @since 1.28 + */ + public function changeTTL( $key, $expiry = 0 ) { + $value = $this->get( $key ); + + return ( $value === false ) ? false : $this->set( $key, $value, $expiry ); + } + /** * Acquire an advisory lock on a key string * @@ -736,4 +751,34 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { public function makeKey() { return $this->makeKeyInternal( $this->keyspace, func_get_args() ); } + + /** + * @param integer $flag ATTR_* class constant + * @return integer QOS_* class constant + * @since 1.28 + */ + public function getQoS( $flag ) { + return isset( $this->attrMap[$flag] ) ? $this->attrMap[$flag] : self::QOS_UNKNOWN; + } + + /** + * Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map + * + * @param BagOStuff[] $bags + * @return integer[] Resulting flag map (class ATTR_* constant => class QOS_* constant) + */ + protected function mergeFlagMaps( array $bags ) { + $map = []; + foreach ( $bags as $bag ) { + foreach ( $bag->attrMap as $attr => $rank ) { + if ( isset( $map[$attr] ) ) { + $map[$attr] = min( $map[$attr], $rank ); + } else { + $map[$attr] = $rank; + } + } + } + + return $map; + } }