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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Illuminate/CachedRouting/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function cache($filename, Closure $callback, $cacheMinutes = 1440)
return null;
}

$cacher = $this->container['cache'];
$cacher = $this->getRouteCacher();
$cacheKey = $this->getCacheKey($filename);

// Check if the current route group is cached.
Expand Down Expand Up @@ -113,9 +113,20 @@ public function cache($filename, Closure $callback, $cacheMinutes = 1440)
*/
public function clearCache($filename)
{
$cacher = $this->container['cache'];
$this->getRouteCacher()->forget($this->getCacheKey($filename));
}

$cacher->forget($this->getCacheKey($filename));
/**
* Get the cache store used to persist compiled routes.
*
* Always the local "file" store so that booting the application (web or
* artisan) never depends on a networked cache such as Redis.
*
* @return \Illuminate\Cache\Repository
*/
protected function getRouteCacher()
{
return $this->container['cache']->driver('file');
}

/**
Expand Down
15 changes: 13 additions & 2 deletions tests/CachedRouting/RoutingIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Illuminate\Cache\CacheManager;
use Illuminate\CachedRouting\Router;
use Illuminate\Config\Repository;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application;
use Illuminate\Session\SessionManager;
use Illuminate\Support\Facades\Facade;
Expand All @@ -51,6 +52,8 @@ class RoutingIntegrationTest extends TestCase
*/
protected ?Application $app = null;

protected static ?string $cachePath = null;

/**
* Setup the test environment.
*/
Expand All @@ -61,6 +64,13 @@ protected function setUp(): void
}
}

protected function tearDown(): void
{
if (self::$cachePath !== null) {
(new Filesystem)->deleteDirectory(self::$cachePath);
}
}

/**
* Refresh the application instance.
*/
Expand All @@ -83,8 +93,10 @@ protected function refreshApplication(): void

$this->app['config'] = new Repository($loader, $this->app['env']);

$this->app['files'] = new Filesystem;
$this->app['cache'] = new CacheManager($this->app);
$this->app['config']['cache.driver'] = 'array';
$this->app['config']['cache.driver'] = 'file';
$this->app['config']['cache.path'] = self::$cachePath = sys_get_temp_dir() . '/l42x-route-cache-' . uniqid();

$this->app['session'] = new SessionManager($this->app);
$this->app['config']['session.driver'] = 'array';
Expand Down Expand Up @@ -150,7 +162,6 @@ public function testCacheRoutesNoTtl(): void
}, 0);

static::assertNull($key, 'Cache key should be null with TTL=0');
static::assertFalse($this->app->cache->has($key), 'Key should not be stored in cache');
static::assertEquals(1, $router->getRoutes()->count(), 'Route must be added to router');
}

Expand Down
Loading