diff options
Diffstat (limited to 'lib/private/Memcache/CADTrait.php')
-rw-r--r-- | lib/private/Memcache/CADTrait.php | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/private/Memcache/CADTrait.php b/lib/private/Memcache/CADTrait.php index bb010e238dc..d0f6611c4f3 100644 --- a/lib/private/Memcache/CADTrait.php +++ b/lib/private/Memcache/CADTrait.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -35,4 +36,21 @@ trait CADTrait { return false; } } + + public function ncad(string $key, mixed $old): bool { + //no native cad, emulate with locking + if ($this->add($key . '_lock', true)) { + $value = $this->get($key); + if ($value !== null && $value !== $old) { + $this->remove($key); + $this->remove($key . '_lock'); + return true; + } else { + $this->remove($key . '_lock'); + return false; + } + } else { + return false; + } + } } |