@@ -68,6 +68,33 @@ method can be safely called repeatedly, even if the lock is already acquired.
68
68
across several requests. To disable the automatic release behavior, set the
69
69
third argument of the ``createLock() `` method to ``false ``.
70
70
71
+ Serializing Locks
72
+ ------------------
73
+
74
+ The ``Key `` contains the state of the ``Lock`` and can be serialized. This
75
+ allows the user to begin a long job in a process by acquiring the lock, and
76
+ to continue the job in an other process within the same lock.::
77
+
78
+ use Symfony\Component\Lock\Key;
79
+ use Symfony\Component\Lock\Lock;
80
+
81
+ $key = new Key('article.'.$article->getId());
82
+ $lock = new Lock($key, $this->store, 300, false);
83
+ $lock->acquire(true);
84
+
85
+ $this->bus->dispatch(new RefreshTaxonomy($article, $key));
86
+
87
+ .. note::
88
+
89
+ Don't forget to disable the autoRelease to avoid releasing the lock when
90
+ the destructor will be called.
91
+
92
+ All stores are not compatible with serialization and cross-process locking:
93
+ For instance the kernel will automatically releases Semaphores acquires by the
94
+ :ref:`SemaphoreStore <lock-store-semaphore>` store.
95
+ Wen a lock is acquired with such store, and hte application try to serialize
96
+ the key, and exception will be thrown
97
+
71
98
.. _lock-blocking-locks:
72
99
73
100
Blocking Locks
@@ -286,17 +313,17 @@ Locks are created and managed in ``Stores``, which are classes that implement
286
313
287
314
The component includes the following built-in store types:
288
315
289
- ============================================ ====== ======== ======== =======
290
- Store Scope Blocking Expiring Sharing
291
- ============================================ ====== ======== ======== =======
292
- :ref: `FlockStore <lock-store-flock >` local yes no yes
293
- :ref: `MemcachedStore <lock-store-memcached >` remote no yes no
294
- :ref: `MongoDbStore <lock-store-mongodb >` remote no yes no
295
- :ref: `PdoStore <lock-store-pdo >` remote no yes no
296
- :ref: `RedisStore <lock-store-redis >` remote no yes yes
297
- :ref: `SemaphoreStore <lock-store-semaphore >` local yes no no
298
- :ref: `ZookeeperStore <lock-store-zookeeper >` remote no no no
299
- ============================================ ====== ======== ======== =======
316
+ ============================================ ====== ========= ======== ======== =======
317
+ Store Scope Serialize Blocking Expiring Sharing
318
+ ============================================ ====== ========= ======== ======== =======
319
+ :ref: `FlockStore <lock-store-flock >` local no yes no yes
320
+ :ref: `MemcachedStore <lock-store-memcached >` remote yes no yes no
321
+ :ref: `MongoDbStore <lock-store-mongodb >` remote yes no yes no
322
+ :ref: `PdoStore <lock-store-pdo >` remote yes no yes no
323
+ :ref: `RedisStore <lock-store-redis >` remote yes no yes yes
324
+ :ref: `SemaphoreStore <lock-store-semaphore >` local no yes no no
325
+ :ref: `ZookeeperStore <lock-store-zookeeper >` remote no no no no
326
+ ============================================ ====== ========= ======== ======== =======
300
327
301
328
.. _lock-store-flock :
302
329
0 commit comments