diff options
Diffstat (limited to 'lib/private/Memcache/CADTrait.php')
-rw-r--r-- | lib/private/Memcache/CADTrait.php | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/private/Memcache/CADTrait.php b/lib/private/Memcache/CADTrait.php index a0843fc7731..d0f6611c4f3 100644 --- a/lib/private/Memcache/CADTrait.php +++ b/lib/private/Memcache/CADTrait.php @@ -1,23 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OC\Memcache; @@ -50,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; + } + } } |