summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2022-06-17 18:09:35 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-06-17 18:32:14 +0200
commit90104bc1c448c6da2fd3e052fca75bb3fb261c87 (patch)
treecbe86e65a0eeeb7cd9c615d2ab81eff76e1e04a1 /lib
parent3f97bcdc75a0479f79ac7fa9210a7cb74f371aff (diff)
downloadnextcloud-server-90104bc1c448c6da2fd3e052fca75bb3fb261c87.tar.gz
nextcloud-server-90104bc1c448c6da2fd3e052fca75bb3fb261c87.zip
memcached should not throw arbitrary exceptions
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Memcache/Memcached.php30
1 files changed, 6 insertions, 24 deletions
diff --git a/lib/private/Memcache/Memcached.php b/lib/private/Memcache/Memcached.php
index 84f220e8a17..7d512d4d1ae 100644
--- a/lib/private/Memcache/Memcached.php
+++ b/lib/private/Memcache/Memcached.php
@@ -63,7 +63,7 @@ class Memcached extends Cache implements IMemcache {
\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
@@ -119,10 +119,7 @@ class Memcached extends Cache implements IMemcache {
} else {
$result = self::$cache->set($this->getNameSpace() . $key, $value);
}
- if ($result !== true) {
- $this->verifyReturnCode();
- }
- return $result;
+ return $result || $this->isSuccess();
}
public function hasKey($key) {
@@ -132,10 +129,7 @@ class Memcached extends Cache implements IMemcache {
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 = '') {
@@ -151,14 +145,10 @@ class Memcached extends Cache implements IMemcache {
* @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();
}
/**
@@ -200,15 +190,7 @@ class Memcached extends Cache implements IMemcache {
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;
}
}