Skip to content

Commit ec31e4f

Browse files
committed
Clear real time facades when running artisan cache:clear
1 parent ecfd0c4 commit ec31e4f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Illuminate/Cache/FileStore.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ public function flush()
151151
}
152152
}
153153

154+
foreach ($this->files->files($this->directory) as $file) {
155+
if (preg_match('/facade-.*\.php$/', $file)) {
156+
if (! $this->files->delete($file)) {
157+
return false;
158+
}
159+
}
160+
}
161+
154162
return true;
155163
}
156164

tests/Cache/CacheFileStoreTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ public function testFlushIgnoreNonExistingDirectory()
167167
$this->assertFalse($result, 'Flush should not clean directory');
168168
}
169169

170+
public function testFlushCleansRealTimeFacades()
171+
{
172+
$files = $this->mockFilesystem();
173+
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->will($this->returnValue(true));
174+
$files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->will($this->returnValue([]));
175+
$files->expects($this->once())->method('files')->with($this->equalTo(__DIR__))->will($this->returnValue(['/facade-XXX.php']));
176+
$files->expects($this->once())->method('delete')->with($this->equalTo('/facade-XXX.php'))->will($this->returnValue(true));
177+
178+
$store = new FileStore($files, __DIR__);
179+
$result = $store->flush();
180+
$this->assertTrue($result, 'Flush failed');
181+
}
182+
170183
protected function mockFilesystem()
171184
{
172185
return $this->createMock('Illuminate\Filesystem\Filesystem');

0 commit comments

Comments
 (0)