* (which will be false if not present), and takes the arguments:
* (this BagOStuff, cache key, current value, TTL).
* The TTL parameter is reference set to $exptime. It can be overriden in the callback.
+ * If the callback returns false, then the current value will be unchanged (including TTL).
*
* @param string $key
* @param callable $callback Callback method to be executed
function () use ( $key, $expiry, $fname ) {
$this->clearLastError();
if ( $this->add( "{$key}:lock", 1, $expiry ) ) {
- return true; // locked!
+ return WaitConditionLoop::CONDITION_REACHED; // locked!
} elseif ( $this->getLastError() ) {
$this->logger->warning(
$fname . ' failed due to I/O error for {key}.',
return $res;
}
+ /**
+ * Batch deletion
+ * @param string[] $keys List of keys
+ * @param int $flags Bitfield of BagOStuff::WRITE_* constants
+ * @return bool Success
+ * @since 1.33
+ */
+ public function deleteMulti( array $keys, $flags = 0 ) {
+ $res = true;
+ foreach ( $keys as $key ) {
+ $res = $this->delete( $key, $flags ) && $res;
+ }
+
+ return $res;
+ }
+
/**
* Insertion
* @param string $key
* @param int $flags Bitfield of BagOStuff::WRITE_* constants (since 1.33)
* @return bool Success
*/
- public function add( $key, $value, $exptime = 0, $flags = 0 ) {
- // @note: avoid lock() here since that method uses *this* method by default
- if ( $this->get( $key ) === false ) {
- return $this->set( $key, $value, $exptime, $flags );
- }
-
- return false; // key already set
- }
+ abstract public function add( $key, $value, $exptime = 0, $flags = 0 );
/**
* Increase stored value of $key by $value while preserving its TTL