diff options
Diffstat (limited to 'lib/private/Memcache')
-rw-r--r-- | lib/private/Memcache/LoggerWrapperCache.php | 10 | ||||
-rw-r--r-- | lib/private/Memcache/ProfilerWrapperCache.php | 10 | ||||
-rw-r--r-- | lib/private/Memcache/Redis.php | 17 |
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(); } |