diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index d445f5fc7c23..6c504bad04e5 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -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 ); diff --git a/tests/Integration/Cache/FileCacheLockTest.php b/tests/Integration/Cache/FileCacheLockTest.php index 575f1220b852..c71c8aeab053 100644 --- a/tests/Integration/Cache/FileCacheLockTest.php +++ b/tests/Integration/Cache/FileCacheLockTest.php @@ -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 @@ -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); @@ -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(); + } }