From b3750a297753cd585740e0ffdf380940654c6a43 Mon Sep 17 00:00:00 2001 From: Mathias Grimm Date: Fri, 9 Jan 2026 17:44:25 -0300 Subject: [PATCH 1/3] Adding Cache::withoutOverlapping --- cache.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cache.md b/cache.md index 37158e0a89..661e28f1d5 100644 --- a/cache.md +++ b/cache.md @@ -13,6 +13,7 @@ - [Cache Tags](#cache-tags) - [Atomic Locks](#atomic-locks) - [Managing Locks](#managing-locks) + - [Without Overlapping](#without-overlapping) - [Managing Locks Across Processes](#managing-locks-across-processes) - [Cache Failover](#cache-failover) - [Adding Custom Cache Drivers](#adding-custom-cache-drivers) @@ -501,6 +502,27 @@ Cache::lock('foo', 10)->block(5, function () { }); ``` + +### Without Overlapping + +The `withoutOverlapping` method provides a simpler syntax for executing a callback while holding an atomic lock: + +```php +Cache::withoutOverlapping('foo', function () { + // Lock acquired for 600 seconds after waiting a maximum of 10 seconds... +}); +``` + +By default, the lock will be held for a maximum of 600 seconds, and the method will wait up to 10 seconds to acquire the lock. You may customize these values by passing additional arguments to the method: + +```php +Cache::withoutOverlapping('foo', function () { + // Lock acquired for 120 seconds after waiting a maximum of 5 seconds... +}, lockSeconds: 120, waitSeconds: 5); +``` + +If the lock cannot be acquired within the specified wait time, an `Illuminate\Contracts\Cache\LockTimeoutException` will be thrown. + ### Managing Locks Across Processes From 17bbc59445cccd460cef5c2cef64fef9e81169ce Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 13 Jan 2026 09:07:53 -0600 Subject: [PATCH 2/3] Formatting --- cache.md | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/cache.md b/cache.md index 661e28f1d5..bcd7d86d55 100644 --- a/cache.md +++ b/cache.md @@ -13,8 +13,8 @@ - [Cache Tags](#cache-tags) - [Atomic Locks](#atomic-locks) - [Managing Locks](#managing-locks) - - [Without Overlapping](#without-overlapping) - [Managing Locks Across Processes](#managing-locks-across-processes) + - [Locks and Function Invocations](#locks-and-function-invocations) - [Cache Failover](#cache-failover) - [Adding Custom Cache Drivers](#adding-custom-cache-drivers) - [Writing the Driver](#writing-the-driver) @@ -502,27 +502,6 @@ Cache::lock('foo', 10)->block(5, function () { }); ``` - -### Without Overlapping - -The `withoutOverlapping` method provides a simpler syntax for executing a callback while holding an atomic lock: - -```php -Cache::withoutOverlapping('foo', function () { - // Lock acquired for 600 seconds after waiting a maximum of 10 seconds... -}); -``` - -By default, the lock will be held for a maximum of 600 seconds, and the method will wait up to 10 seconds to acquire the lock. You may customize these values by passing additional arguments to the method: - -```php -Cache::withoutOverlapping('foo', function () { - // Lock acquired for 120 seconds after waiting a maximum of 5 seconds... -}, lockSeconds: 120, waitSeconds: 5); -``` - -If the lock cannot be acquired within the specified wait time, an `Illuminate\Contracts\Cache\LockTimeoutException` will be thrown. - ### Managing Locks Across Processes @@ -552,6 +531,27 @@ If you would like to release a lock without respecting its current owner, you ma Cache::lock('processing')->forceRelease(); ``` + +### Locks and Function Invocations + +The `withoutOverlapping` method provides a simple syntax for executing a given closure while holding an atomic lock, allowing you to ensure only one instance of the closure is running at a given time across your entire infrastructure: + +```php +Cache::withoutOverlapping('foo', function () { + // Lock acquired for 600 seconds after waiting a maximum of 10 seconds... +}); +``` + +By default, the lock will be held for a maximum of 600 seconds, and the method will wait up to 10 seconds to acquire the lock. You may customize these values by passing additional arguments to the method: + +```php +Cache::withoutOverlapping('foo', function () { + // Lock acquired for 120 seconds after waiting a maximum of 5 seconds... +}, lockSeconds: 120, waitSeconds: 5); +``` + +If the lock cannot be acquired within the specified wait time, an `Illuminate\Contracts\Cache\LockTimeoutException` will be thrown. + ## Cache Failover From 28a593114763a4e5b7eb841022d477647c6093d2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 13 Jan 2026 09:10:33 -0600 Subject: [PATCH 3/3] Update cache.md --- cache.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache.md b/cache.md index bcd7d86d55..afbe000d0d 100644 --- a/cache.md +++ b/cache.md @@ -538,11 +538,11 @@ The `withoutOverlapping` method provides a simple syntax for executing a given c ```php Cache::withoutOverlapping('foo', function () { - // Lock acquired for 600 seconds after waiting a maximum of 10 seconds... + // Lock acquired after waiting a maximum of 10 seconds... }); ``` -By default, the lock will be held for a maximum of 600 seconds, and the method will wait up to 10 seconds to acquire the lock. You may customize these values by passing additional arguments to the method: +By default, the lock will not be released until the closure finishes executing, and the method will wait up to 10 seconds to acquire the lock. You may customize these values by passing additional arguments to the method: ```php Cache::withoutOverlapping('foo', function () {