Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,11 @@ public function restoreLock($name, $owner)
public function forget($key)
{
if ($this->files->exists($file = $this->path($key))) {
$this->files->delete($this->path("illuminate:cache:flexible:created:{$key}"));

return $this->files->delete($file);
return tap($this->files->delete($file), function ($forgotten) use ($key) {
if ($forgotten && $this->files->exists($file = $this->path("illuminate:cache:flexible:created:{$key}"))) {
$this->files->delete($file);
}
});
}

return false;
Expand Down
44 changes: 44 additions & 0 deletions tests/Cache/CacheFileStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Mockery as m;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -330,6 +331,49 @@ public function testFlushIgnoreNonExistingDirectory()
$this->assertFalse($result, 'Flush should not clean directory');
}

public function testItHandlesForgettingNonFlexibleKeys()
{
$store = new FileStore(new Filesystem, __DIR__);

$key = Str::random();
$path = $store->path($key);
$flexiblePath = "illuminate:cache:flexible:created:{$key}";

$store->put($key, 'value', 5);

$this->assertFileExists($path);
$this->assertFileDoesNotExist($flexiblePath);

$store->forget($key);

$this->assertFileDoesNotExist($path);
$this->assertFileDoesNotExist($flexiblePath);
}

public function itOnlyForgetsFlexibleKeysIfParentIsForgotten()
{
$store = new FileStore(new Filesystem, __DIR__);

$key = Str::random();
$path = $store->path($key);
$flexiblePath = "illuminate:cache:flexible:created:{$key}";

touch($flexiblePath);

$this->assertFileDoesNotExist($path);
$this->assertFileExists($flexiblePath);

$store->forget($key);

$this->assertFileDoesNotExist($path);
$this->assertFileExists($flexiblePath);

$store->put($key, 'value', 5);

$this->assertFileDoesNotExist($path);
$this->assertFileDoesNotExist($flexiblePath);
}

protected function mockFilesystem()
{
return $this->createMock(Filesystem::class);
Expand Down