Skip to content

Commit 4d9383c

Browse files
committed
only forget when parent key is forgotten
1 parent 88e8d7e commit 4d9383c

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/Illuminate/Cache/FileStore.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,13 @@ public function restoreLock($name, $owner)
247247
*/
248248
public function forget($key)
249249
{
250-
if ($this->files->exists($file = $this->path("illuminate:cache:flexible:created:{$key}"))) {
251-
$this->files->delete($file);
252-
}
253250

254251
if ($this->files->exists($file = $this->path($key))) {
255-
return $this->files->delete($file);
252+
return tap($this->files->delete($file), function ($forgotten) use ($key) {
253+
if ($forgotten && $this->files->exists($file = $this->path("illuminate:cache:flexible:created:{$key}"))) {
254+
$this->files->delete($file);
255+
}
256+
});
256257
}
257258

258259
return false;

tests/Cache/CacheFileStoreTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,30 @@ public function testItHandlesForgettingNonFlexibleKeys()
350350
$this->assertFileDoesNotExist($flexiblePath);
351351
}
352352

353+
public function itOnlyForgetsFlexibleKeysIfParentIsForgotten()
354+
{
355+
$store = new FileStore(new Filesystem, __DIR__);
356+
357+
$key = Str::random();
358+
$path = $store->path($key);
359+
$flexiblePath = "illuminate:cache:flexible:created:{$key}";
360+
361+
touch($flexiblePath);
362+
363+
$this->assertFileDoesNotExist($path);
364+
$this->assertFileExists($flexiblePath);
365+
366+
$store->forget($key);
367+
368+
$this->assertFileDoesNotExist($path);
369+
$this->assertFileExists($flexiblePath);
370+
371+
$store->put($key, 'value', 5);
372+
373+
$this->assertFileDoesNotExist($path);
374+
$this->assertFileDoesNotExist($flexiblePath);
375+
}
376+
353377
protected function mockFilesystem()
354378
{
355379
return $this->createMock(Filesystem::class);

0 commit comments

Comments
 (0)