3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core\Lock\Capability;
24 use Friendica\Core\Cache\Enum\Duration;
25 use Friendica\Core\Lock\Exception\LockPersistenceException;
33 * Checks, if a key is currently locked to a or my process
35 * @param string $key The name of the lock
37 public function isLocked(string $key): bool;
41 * Acquires a lock for a given name
43 * @param string $key The Name of the lock
44 * @param integer $timeout Seconds until we give up
45 * @param integer $ttl Seconds The lock lifespan, must be one of the Cache constants
47 * @throws LockPersistenceException In case the underlying persistence throws errors
49 public function acquire(string $key, int $timeout = 120, int $ttl = Duration::FIVE_MINUTES): bool;
52 * Releases a lock if it was set by us
54 * @param string $key The Name of the lock
55 * @param bool $override Overrides the lock to get released
57 * @return bool Was the unlock successful?
59 * @throws LockPersistenceException In case the underlying persistence throws errors
61 public function release(string $key, bool $override = false): bool;
64 * Releases all lock that were set by us
66 * @param bool $override Override to release all locks
68 * @return bool Was the unlock of all locks successful?
70 * @throws LockPersistenceException In case the underlying persistence throws errors
72 public function releaseAll(bool $override = false): bool;
75 * Returns the name of the current lock
77 public function getName(): string;
82 * @param string prefix optional a prefix to search
84 * @return string[] Empty if it isn't supported by the cache driver
86 * @throws LockPersistenceException In case the underlying persistence throws errors
88 public function getLocks(string $prefix = ''): array;