*/
abstract public function delete( $key, $flags = 0 );
+ /**
+ * Insert an item if it does not already exist
+ *
+ * @param string $key
+ * @param mixed $value
+ * @param int $exptime
+ * @param int $flags Bitfield of BagOStuff::WRITE_* constants (since 1.33)
+ * @return bool Success
+ */
+ abstract public function add( $key, $value, $exptime = 0, $flags = 0 );
+
/**
* Merge changes into the existing cache value (possibly creating a new one)
*
return $res;
}
- /**
- * Insertion
- * @param string $key
- * @param mixed $value
- * @param int $exptime
- * @param int $flags Bitfield of BagOStuff::WRITE_* constants (since 1.33)
- * @return bool Success
- */
- abstract public function add( $key, $value, $exptime = 0, $flags = 0 );
-
/**
* Increase stored value of $key by $value while preserving its TTL
* @param string $key Key to increase
}
}
+ /**
+ * @param int $exptime
+ * @return bool
+ */
+ protected function expiryIsRelative( $exptime ) {
+ return ( $exptime != 0 && $exptime < ( 10 * self::TTL_YEAR ) );
+ }
+
/**
* Convert an optionally relative time to an absolute time
* @param int $exptime
* @return int
*/
- protected function convertExpiry( $exptime ) {
- if ( $exptime != 0 && $exptime < ( 10 * self::TTL_YEAR ) ) {
+ protected function convertToExpiry( $exptime ) {
+ if ( $this->expiryIsRelative( $exptime ) ) {
return (int)$this->getCurrentTime() + $exptime;
} else {
return $exptime;
unset( $this->bag[$key] );
$this->bag[$key] = [
self::KEY_VAL => $value,
- self::KEY_EXP => $this->convertExpiry( $exptime ),
+ self::KEY_EXP => $this->convertToExpiry( $exptime ),
self::KEY_CAS => $this->token . ':' . ++self::$casCounter
];
if ( $exptime == 0 ) {
$encExpiry = $this->getMaxDateTime( $db );
} else {
- $exptime = $this->convertExpiry( $exptime );
+ $exptime = $this->convertToExpiry( $exptime );
$encExpiry = $db->timestamp( $exptime );
}
foreach ( $serverKeys as $tableName => $tableKeys ) {
if ( $exptime == 0 ) {
$encExpiry = $this->getMaxDateTime( $db );
} else {
- $exptime = $this->convertExpiry( $exptime );
+ $exptime = $this->convertToExpiry( $exptime );
$encExpiry = $db->timestamp( $exptime );
}
// (T26425) use a replace if the db supports it instead of
$db = $this->getDB( $serverIndex );
$db->update(
$tableName,
- [ 'exptime' => $db->timestamp( $this->convertExpiry( $expiry ) ) ],
+ [ 'exptime' => $db->timestamp( $this->convertToExpiry( $expiry ) ) ],
[ 'keyname' => $key, 'exptime > ' . $db->addQuotes( $db->timestamp( time() ) ) ],
__METHOD__
);