Added Unittests for cache

fixed Lock & Cache bugs
This commit is contained in:
Philipp Holzer 2018-07-07 19:46:16 +02:00
parent 1dafaa69c5
commit 80a4e6263f
No known key found for this signature in database
GPG key ID: 58160D7D6AF942B6
18 changed files with 317 additions and 25 deletions

View file

@ -3,6 +3,7 @@
namespace Friendica\Core\Lock;
use dba;
use Friendica\Core\Cache;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
@ -14,7 +15,7 @@ class DatabaseLockDriver extends AbstractLockDriver
/**
* (@inheritdoc)
*/
public function acquireLock($key, $timeout = 120)
public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
{
$got_lock = false;
$start = time();
@ -28,16 +29,14 @@ class DatabaseLockDriver extends AbstractLockDriver
// We want to lock something that was already locked by us? So we got the lock.
if ($lock['pid'] == getmypid()) {
$got_lock = true;
$this->markAcquire($key);
}
}
if (!$lock['locked']) {
dba::update('locks', ['locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + 300seconds')], ['name' => $key]);
dba::update('locks', ['locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds')], ['name' => $key]);
$got_lock = true;
$this->markAcquire($key);
}
} else {
dba::insert('locks', ['name' => $key, 'locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + 300seconds')]);
dba::insert('locks', ['name' => $key, 'locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds')]);
$got_lock = true;
$this->markAcquire($key);
}