4 * @file src/Core/Lock.php
5 * @brief Functions for preventing parallel execution of functions
8 namespace Friendica\Core;
10 use Friendica\BaseObject;
11 use Friendica\Core\Cache\Cache;
12 use Friendica\Core\Lock\ILock;
15 * This class contain Functions for preventing parallel execution of functions
17 class Lock extends BaseObject
20 * @brief Acquires a lock for a given name
22 * @param string $key Name of the lock
23 * @param integer $timeout Seconds until we give up
24 * @param integer $ttl The Lock lifespan, must be one of the Cache constants
26 * @return boolean Was the lock successful?
29 public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
31 return self::getClass(ILock::class)->acquireLock($key, $timeout, $ttl);
35 * @brief Releases a lock if it was set by us
37 * @param string $key Name of the lock
38 * @param bool $override Overrides the lock to get releases
43 public static function release($key, $override = false)
45 return self::getClass(ILock::class)->releaseLock($key, $override);
49 * @brief Releases all lock that were set by us
53 public static function releaseAll()
55 self::getClass(ILock::class)->releaseAll();