Skip to content

[Lock] Renamed the Lock factory class #11931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions components/lock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ Locks are used to guarantee exclusive access to some shared resource. In
Symfony applications, you can use locks for example to ensure that a command is
not executed more than once at the same time (on the same or different servers).

Locks are created using a :class:`Symfony\\Component\\Lock\\Factory` class,
Locks are created using a :class:`Symfony\\Component\\Lock\\LockFactory` class,
which in turn requires another class to manage the storage of locks::

use Symfony\Component\Lock\Factory;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\Store\SemaphoreStore;

$store = new SemaphoreStore();
$factory = new Factory($store);
$factory = new LockFactory($store);

The lock is created by calling the :method:`Symfony\\Component\\Lock\\Factory::createLock`
.. versionadded:: 4.4

The ``Symfony\Component\Lock\LockFactory`` class was introduced in Symfony
4.4. In previous versions it was called ``Symfony\Component\Lock\Factory``.

The lock is created by calling the :method:`Symfony\\Component\\Lock\\LockFactory::createLock`
method. Its first argument is an arbitrary string that represents the locked
resource. Then, a call to the :method:`Symfony\\Component\\Lock\\LockInterface::acquire`
method will try to acquire the lock::
Expand All @@ -56,7 +61,7 @@ method can be safely called repeatedly, even if the lock is already acquired.
Unlike other implementations, the Lock Component distinguishes locks
instances even when they are created for the same resource. If a lock has
to be used by several services, they should share the same ``Lock`` instance
returned by the ``Factory::createLock`` method.
returned by the ``LockFactory::createLock`` method.

.. tip::

Expand All @@ -77,13 +82,13 @@ until the lock is acquired.
Some of the built-in ``Store`` classes support this feature. When they don't,
they can be decorated with the ``RetryTillSaveStore`` class::

use Symfony\Component\Lock\Factory;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\Store\RedisStore;
use Symfony\Component\Lock\Store\RetryTillSaveStore;

$store = new RedisStore(new \Predis\Client('tcp://localhost:6379'));
$store = new RetryTillSaveStore($store);
$factory = new Factory($store);
$factory = new LockFactory($store);

$lock = $factory->createLock('notification-flush');
$lock->acquire(true);
Expand Down