aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Memcache
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2023-03-29 18:03:03 +0200
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2023-12-22 09:54:13 +0000
commit6ba6c95bab863197fd2922ac2e83567d643ebecc (patch)
treec22b45934840a617c9b76fd033604c8e059e3d35 /lib/private/Memcache
parentfecb3ea41cd9fe2e7f12fdb4b9b9a24845de281a (diff)
downloadnextcloud-server-6ba6c95bab863197fd2922ac2e83567d643ebecc.tar.gz
nextcloud-server-6ba6c95bab863197fd2922ac2e83567d643ebecc.zip
restore shared lock ttl when releasing
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Memcache')
-rw-r--r--lib/private/Memcache/LoggerWrapperCache.php10
-rw-r--r--lib/private/Memcache/ProfilerWrapperCache.php10
-rw-r--r--lib/private/Memcache/Redis.php17
3 files changed, 35 insertions, 2 deletions
diff --git a/lib/private/Memcache/LoggerWrapperCache.php b/lib/private/Memcache/LoggerWrapperCache.php
index 55c0e76db79..55d5104dedb 100644
--- a/lib/private/Memcache/LoggerWrapperCache.php
+++ b/lib/private/Memcache/LoggerWrapperCache.php
@@ -167,10 +167,18 @@ class LoggerWrapperCache extends Cache implements IMemcacheTTL {
}
/** @inheritDoc */
- public function setTTL($key, $ttl) {
+ public function setTTL(string $key, int $ttl) {
$this->wrappedCache->setTTL($key, $ttl);
}
+ public function getTTL(string $key): int|false {
+ return $this->wrappedCache->getTTL($key);
+ }
+
+ public function compareSetTTL(string $key, mixed $value, int $ttl): bool {
+ return $this->wrappedCache->compareSetTTL($key, $value, $ttl);
+ }
+
public static function isAvailable(): bool {
return true;
}
diff --git a/lib/private/Memcache/ProfilerWrapperCache.php b/lib/private/Memcache/ProfilerWrapperCache.php
index 6e76989dddd..a5cb667114c 100644
--- a/lib/private/Memcache/ProfilerWrapperCache.php
+++ b/lib/private/Memcache/ProfilerWrapperCache.php
@@ -183,10 +183,18 @@ class ProfilerWrapperCache extends AbstractDataCollector implements IMemcacheTTL
}
/** @inheritDoc */
- public function setTTL($key, $ttl) {
+ public function setTTL(string $key, int $ttl) {
$this->wrappedCache->setTTL($key, $ttl);
}
+ public function getTTL(string $key): int|false {
+ return $this->wrappedCache->getTTL($key);
+ }
+
+ public function compareSetTTL(string $key, mixed $value, int $ttl): bool {
+ return $this->wrappedCache->compareSetTTL($key, $value, $ttl);
+ }
+
public function offsetExists($offset): bool {
return $this->hasKey($offset);
}
diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php
index bde25a3385a..7bd29d1cecf 100644
--- a/lib/private/Memcache/Redis.php
+++ b/lib/private/Memcache/Redis.php
@@ -181,6 +181,23 @@ class Redis extends Cache implements IMemcacheTTL {
$this->getCache()->expire($this->getPrefix() . $key, $ttl);
}
+ public function getTTL(string $key): int|false {
+ $ttl = $this->getCache()->ttl($this->getPrefix() . $key);
+ return $ttl > 0 ? (int)$ttl : false;
+ }
+
+ public function compareSetTTL(string $key, mixed $value, int $ttl): bool {
+ $fullKey = $this->getPrefix() . $key;
+ $redis = $this->getCache();
+ if ($this->get($key) === $value) {
+ $result = $redis->multi()
+ ->expire($fullKey, $ttl)
+ ->exec();
+ return $result !== false;
+ }
+ return false;
+ }
+
public static function isAvailable(): bool {
return \OC::$server->getGetRedisFactory()->isAvailable();
}