Skip to content

Conversation

@mathiasgrimm
Copy link
Contributor

@mathiasgrimm mathiasgrimm commented Jan 7, 2026

Add Cache::withoutOverlapping() method

Description

This PR adds a new atomic() method to the Cache Repository that provides a cleaner API for executing callbacks within atomic locks.

Before

Cache::lock('my-lock-key', 600)->block(10, function () {
    // critical section
});

After

Cache::withoutOverlapping('my-lock-key', function () {
    // critical section
});

Method Signature

public function withoutOverlapping($key, callable $callback, $lockSeconds = 600, $waitSeconds = 10, $owner = null)

Parameters:

  • $key - The lock key name
  • $callback - The callback to execute within the lock
  • $lockSeconds - How long the lock should be held (default: 600)
  • $waitSeconds - How long to wait to acquire the lock (default: 10)
  • $owner - Optional owner identifier for distributed lock restoration

Throws: LockTimeoutException if the lock cannot be acquired within $waitSeconds

Default Values

The defaults of 10 seconds for both $lockSeconds and $waitSeconds match the existing session/route blocking defaults in the framework (SessionManager::defaultRouteBlockLockSeconds() and Route::block()).

@mathiasgrimm mathiasgrimm changed the title [12.x] Add Cache::atomic to wrap Cache::lock()->block() [12.x] Add Cache::atomic() to wrap Cache::lock()->block() Jan 7, 2026
@taylorotwell taylorotwell merged commit 1c58a88 into 12.x Jan 8, 2026
71 checks passed
@mathiasgrimm mathiasgrimm changed the title [12.x] Add Cache::atomic() to wrap Cache::lock()->block() [12.x] Add Cache::withoutOverlapping() to wrap Cache::lock()->block() Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants