Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function lock($name, $seconds = 0, $owner = null)

return new FileLock(
new static($this->files, $this->lockDirectory ?? $this->directory, $this->filePermission),
$name,
"file-store-lock:{$name}",
$seconds,
$owner
);
Expand Down
23 changes: 23 additions & 0 deletions tests/Integration/Cache/FileCacheLockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Sleep;
use Orchestra\Testbench\Attributes\WithConfig;
use Orchestra\Testbench\TestCase;
use Throwable;

#[WithConfig('cache.default', 'file')]
class FileCacheLockTest extends TestCase
Expand Down Expand Up @@ -100,6 +101,18 @@ public function testOwnerStatusCanBeCheckedAfterRestoringLock()
$this->assertTrue($secondLock->isOwnedByCurrentProcess());
}

public function testCacheRememberReturnsValueWhenLockWithSameKeyExists()
{
$lock = Cache::lock('my-key', 5);
$this->assertTrue($lock->get());

$value = Cache::remember('my-key', 60, fn () => 'expected-value');

$this->assertSame('expected-value', $value);

$lock->release();
}

public function testOtherOwnerDoesNotOwnLockAfterRestore()
{
$firstLock = Cache::lock('foo', 10);
Expand All @@ -123,4 +136,14 @@ public function testExceptionIfBlockCanNotAcquireLock()
$this->expectException(LockTimeoutException::class);
Cache::lock('foo', 10)->block(5);
}

protected function tearDown(): void
{
try {
Cache::lock('foo')->forceRelease();
} catch (Throwable) {
}

parent::tearDown();
}
}