X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FLock%2FCacheLock.php;h=238beb705ce93e986773adef7ec898e41a3ab9b6;hb=de7c026590576e6215abeee5d762680355f61dd1;hp=36a7b4edfb2216703eed9cbe50cf3c19bfea9602;hpb=19777baa793f51e744adb8e3fc12bb857bd111e3;p=friendica.git diff --git a/src/Core/Lock/CacheLock.php b/src/Core/Lock/CacheLock.php index 36a7b4edfb..238beb705c 100644 --- a/src/Core/Lock/CacheLock.php +++ b/src/Core/Lock/CacheLock.php @@ -7,6 +7,11 @@ use Friendica\Core\Cache\IMemoryCache; class CacheLock extends Lock { + /** + * @var string The static prefix of all locks inside the cache + */ + const CACHE_PREFIX = 'lock:'; + /** * @var \Friendica\Core\Cache\ICache; */ @@ -25,7 +30,7 @@ class CacheLock extends Lock /** * (@inheritdoc) */ - public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES) + public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES) { $got_lock = false; $start = time(); @@ -85,6 +90,46 @@ class CacheLock extends Lock return isset($lock) && ($lock !== false); } + /** + * {@inheritDoc} + */ + public function getName() + { + return $this->cache->getName(); + } + + /** + * {@inheritDoc} + */ + public function getLocks(string $prefix = '') + { + $locks = $this->cache->getAllKeys(self::CACHE_PREFIX . $prefix); + + array_walk($locks, function (&$lock, $key) { + $lock = substr($lock, strlen(self::CACHE_PREFIX)); + }); + + return $locks; + } + + /** + * {@inheritDoc} + */ + public function releaseAll($override = false) + { + $success = parent::releaseAll($override); + + $locks = $this->getLocks(); + + foreach ($locks as $lock) { + if (!$this->releaseLock($lock, $override)) { + $success = false; + } + } + + return $success; + } + /** * @param string $key The original key * @@ -92,6 +137,6 @@ class CacheLock extends Lock */ private static function getLockKey($key) { - return "lock:" . $key; + return self::CACHE_PREFIX . $key; } }