function DoctrineDbalPostgreSqlStore::waitAndSaveRead
Overrides BlockingSharedLockStoreInterface::waitAndSaveRead
File
-
vendor/
symfony/ lock/ Store/ DoctrineDbalPostgreSqlStore.php, line 207
Class
- DoctrineDbalPostgreSqlStore
- DoctrineDbalPostgreSqlStore is a PersistingStoreInterface implementation using PostgreSql advisory locks with a Doctrine DBAL Connection.
Namespace
Symfony\Component\Lock\StoreCode
public function waitAndSaveRead(Key $key) : void {
// prevent concurrency within the same connection
// Internal store does not allow blocking mode, because there is no way to acquire one in a single process
$this->getInternalStore()
->saveRead($key);
$lockAcquired = false;
$sql = 'SELECT pg_advisory_lock_shared(:key)';
try {
$this->conn
->executeStatement($sql, [
'key' => $this->getHashedKey($key),
]);
$lockAcquired = true;
} finally {
if (!$lockAcquired) {
$this->getInternalStore()
->delete($key);
}
}
// release lock in case of demotion
$this->unlock($key);
}