]> git.mxchange.org Git - friendica.git/blob - src/Core/Lock/ILock.php
Merge pull request #9039 from MrPetovan/task/frio-accent-scheme
[friendica.git] / src / Core / Lock / ILock.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Core\Lock;
23
24 use Friendica\Core\Cache\Duration;
25
26 /**
27  * Lock Interface
28  */
29 interface ILock
30 {
31         /**
32          * Checks, if a key is currently locked to a or my process
33          *
34          * @param string $key The name of the lock
35          *
36          * @return bool
37          */
38         public function isLocked($key);
39
40         /**
41          *
42          * Acquires a lock for a given name
43          *
44          * @param string  $key     The Name of the lock
45          * @param integer $timeout Seconds until we give up
46          * @param integer $ttl     Seconds The lock lifespan, must be one of the Cache constants
47          *
48          * @return boolean Was the lock successful?
49          */
50         public function acquire($key, $timeout = 120, $ttl = Duration::FIVE_MINUTES);
51
52         /**
53          * Releases a lock if it was set by us
54          *
55          * @param string $key      The Name of the lock
56          * @param bool   $override Overrides the lock to get released
57          *
58          * @return boolean Was the unlock successful?
59          */
60         public function release($key, $override = false);
61
62         /**
63          * Releases all lock that were set by us
64          *
65          * @param bool $override Override to release all locks
66          *
67          * @return boolean Was the unlock of all locks successful?
68          */
69         public function releaseAll($override = false);
70
71         /**
72          * Returns the name of the current lock
73          *
74          * @return string
75          */
76         public function getName();
77
78         /**
79          * Lists all locks
80          *
81          * @param string prefix optional a prefix to search
82          *
83          * @return array Empty if it isn't supported by the cache driver
84          */
85         public function getLocks(string $prefix = '');
86 }