X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FLock%2FCacheLockDriver.php;h=18d441ffea09d5a0910ec6ac3ada461db885ab7c;hb=761bdafa34bfdf1b2b43a3f06ae092e0925898ac;hp=2dd6f3fad9defd290ca4c1fc7c90215d7607ee04;hpb=e41e7d2edd286483b2001b9164ca3039997e7634;p=friendica.git diff --git a/src/Core/Lock/CacheLockDriver.php b/src/Core/Lock/CacheLockDriver.php index 2dd6f3fad9..18d441ffea 100644 --- a/src/Core/Lock/CacheLockDriver.php +++ b/src/Core/Lock/CacheLockDriver.php @@ -2,6 +2,7 @@ namespace Friendica\Core\Lock; +use Friendica\Core\Cache; use Friendica\Core\Cache\IMemoryCacheDriver; class CacheLockDriver extends AbstractLockDriver @@ -24,12 +25,12 @@ class CacheLockDriver extends AbstractLockDriver /** * (@inheritdoc) */ - public function acquireLock($key, $timeout = 120) + public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES) { $got_lock = false; $start = time(); - $cachekey = self::getCacheKey($key); + $cachekey = self::getLockKey($key); do { $lock = $this->cache->get($cachekey); @@ -43,7 +44,7 @@ class CacheLockDriver extends AbstractLockDriver // At first initialize it with "0" $this->cache->add($cachekey, 0); // Now the value has to be "0" because otherwise the key was used by another process meanwhile - if ($this->cache->compareSet($cachekey, 0, getmypid(), 300)) { + if ($this->cache->compareSet($cachekey, 0, getmypid(), $ttl)) { $got_lock = true; $this->markAcquire($key); } @@ -62,7 +63,7 @@ class CacheLockDriver extends AbstractLockDriver */ public function releaseLock($key) { - $cachekey = self::getCacheKey($key); + $cachekey = self::getLockKey($key); $this->cache->compareDelete($cachekey, getmypid()); $this->markRelease($key); @@ -73,7 +74,7 @@ class CacheLockDriver extends AbstractLockDriver */ public function isLocked($key) { - $cachekey = self::getCacheKey($key); + $cachekey = self::getLockKey($key); $lock = $this->cache->get($cachekey); return isset($lock) && ($lock !== false); } @@ -82,7 +83,7 @@ class CacheLockDriver extends AbstractLockDriver * @param string $key The original key * @return string The cache key used for the cache */ - private static function getCacheKey($key) { - return self::getApp()->get_hostname() . ";lock:" . $key; + private static function getLockKey($key) { + return "lock:" . $key; } }