Skip to content

Commit

Permalink
feat: add FileLocatorCached::deleteCache()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 8, 2023
1 parent 40ea549 commit df4920c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions system/Autoloader/FileLocatorCached.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* FileLocator with Cache
*
* There is no FileLocator interface, so this extends FileLocator.
*
* @see \CodeIgniter\Autoloader\FileLocatorCachedTest
*/
final class FileLocatorCached extends FileLocator
{
Expand Down Expand Up @@ -80,6 +82,14 @@ private function saveCache(): void
}
}

/**
* Delete cache data
*/
public function deleteCache(): void
{
$this->cacheHandler->delete($this->cacheKey);
}

protected function getNamespaces()
{
if (isset($this->cache['getNamespaces'])) {
Expand Down
29 changes: 29 additions & 0 deletions tests/system/Autoloader/FileLocatorCachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@
*/
final class FileLocatorCachedTest extends FileLocatorTest
{
private FileVarExportHandler $handler;
private FileLocator $locator;

public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();

// Delete cache file.
$autoloader = new Autoloader();
$handler = new FileVarExportHandler();
$fileLocator = new FileLocator($autoloader);
$locator = new FileLocatorCached($fileLocator, $handler);
$locator->deleteCache();
}

protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -51,4 +64,20 @@ protected function setUp(): void
$fileLocator = new FileLocator($autoloader);
$this->locator = new FileLocatorCached($fileLocator, $this->handler);
}

protected function tearDown(): void
{
$this->locator->__destruct();

parent::tearDown();
}

public function testDeleteCache()
{
$this->assertNotSame([], $this->handler->get('FileLocatorCache'));

$this->locator->deleteCache();

$this->assertFalse($this->handler->get('FileLocatorCache'));
}
}

0 comments on commit df4920c

Please sign in to comment.