Skip to content

Commit

Permalink
Merge pull request #32924 from nextcloud/memcached-binary-protocol
Browse files Browse the repository at this point in the history
Enable binary protocol again
  • Loading branch information
CarlSchwan authored Jun 21, 2022
2 parents f46d839 + 90104bc commit dbc2c23
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions lib/private/Memcache/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct($prefix = '') {
\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,

// Enable Binary Protocol
//\Memcached::OPT_BINARY_PROTOCOL => true,
\Memcached::OPT_BINARY_PROTOCOL => true,
];
/**
* By default enable igbinary serializer if available
Expand Down Expand Up @@ -119,10 +119,7 @@ public function set($key, $value, $ttl = 0) {
} else {
$result = self::$cache->set($this->getNameSpace() . $key, $value);
}
if ($result !== true) {
$this->verifyReturnCode();
}
return $result;
return $result || $this->isSuccess();
}

public function hasKey($key) {
Expand All @@ -132,10 +129,7 @@ public function hasKey($key) {

public function remove($key) {
$result = self::$cache->delete($this->getNameSpace() . $key);
if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
$this->verifyReturnCode();
}
return $result;
return $result || $this->isSuccess() || self::$cache->getResultCode() === \Memcached::RES_NOTFOUND;
}

public function clear($prefix = '') {
Expand All @@ -151,14 +145,10 @@ public function clear($prefix = '') {
* @param mixed $value
* @param int $ttl Time To Live in seconds. Defaults to 60*60*24
* @return bool
* @throws \Exception
*/
public function add($key, $value, $ttl = 0) {
$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
$this->verifyReturnCode();
}
return $result;
return $result || $this->isSuccess();
}

/**
Expand Down Expand Up @@ -200,15 +190,7 @@ public static function isAvailable(): bool {
return extension_loaded('memcached');
}

/**
* @throws \Exception
*/
private function verifyReturnCode() {
$code = self::$cache->getResultCode();
if ($code === \Memcached::RES_SUCCESS) {
return;
}
$message = self::$cache->getResultMessage();
throw new \Exception("Error $code interacting with memcached : $message");
private function isSuccess(): bool {
return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
}
}

0 comments on commit dbc2c23

Please sign in to comment.