Skip to content

Commit df4920c

Browse files
committed
feat: add FileLocatorCached::deleteCache()
1 parent 40ea549 commit df4920c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

system/Autoloader/FileLocatorCached.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* FileLocator with Cache
1919
*
2020
* There is no FileLocator interface, so this extends FileLocator.
21+
*
22+
* @see \CodeIgniter\Autoloader\FileLocatorCachedTest
2123
*/
2224
final class FileLocatorCached extends FileLocator
2325
{
@@ -80,6 +82,14 @@ private function saveCache(): void
8082
}
8183
}
8284

85+
/**
86+
* Delete cache data
87+
*/
88+
public function deleteCache(): void
89+
{
90+
$this->cacheHandler->delete($this->cacheKey);
91+
}
92+
8393
protected function getNamespaces()
8494
{
8595
if (isset($this->cache['getNamespaces'])) {

tests/system/Autoloader/FileLocatorCachedTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@
2222
*/
2323
final class FileLocatorCachedTest extends FileLocatorTest
2424
{
25+
private FileVarExportHandler $handler;
2526
private FileLocator $locator;
2627

28+
public static function tearDownAfterClass(): void
29+
{
30+
parent::tearDownAfterClass();
31+
32+
// Delete cache file.
33+
$autoloader = new Autoloader();
34+
$handler = new FileVarExportHandler();
35+
$fileLocator = new FileLocator($autoloader);
36+
$locator = new FileLocatorCached($fileLocator, $handler);
37+
$locator->deleteCache();
38+
}
39+
2740
protected function setUp(): void
2841
{
2942
parent::setUp();
@@ -51,4 +64,20 @@ protected function setUp(): void
5164
$fileLocator = new FileLocator($autoloader);
5265
$this->locator = new FileLocatorCached($fileLocator, $this->handler);
5366
}
67+
68+
protected function tearDown(): void
69+
{
70+
$this->locator->__destruct();
71+
72+
parent::tearDown();
73+
}
74+
75+
public function testDeleteCache()
76+
{
77+
$this->assertNotSame([], $this->handler->get('FileLocatorCache'));
78+
79+
$this->locator->deleteCache();
80+
81+
$this->assertFalse($this->handler->get('FileLocatorCache'));
82+
}
5483
}

0 commit comments

Comments
 (0)