Skip to content

[Fix][CachedRouting] Persist route cache in local file store - #27

Merged
agissept merged 1 commit into
masterfrom
improvements/local-route-cache
Aug 27, 2026
Merged

[Fix][CachedRouting] Persist route cache in local file store#27
agissept merged 1 commit into
masterfrom
improvements/local-route-cache

Conversation

@agissept

Copy link
Copy Markdown
Member

Summary

CachedRouting\Router::cache()/clearCache() resolved the container's default cache store — which in production is Redis. Routes are loaded during application boot (Foundation/start.phpapp/routes.phpRoute::cache()), so every web request and artisan command — including queue:work — issued a Redis GET at boot. When Redis was unreachable, boot itself failed:

Predis\Connection\ConnectionException: Connection refused [tcp://127.0.0.1:6390]
  ... Illuminate\Cache\RedisStore->get('routes.cache.v2...')
  ... Illuminate\CachedRouting\Router->cache(...)   (api_routes.php:3)
  ... require routes.php                             (start.php)
  ... Illuminate\Console\Application::make() → $app->boot()  (artisan)

Route cache is a build-time artifact, deterministic per release — it belongs on local disk, exactly like modern Laravel's file-based route cache (bootstrap/cache/routes-v7.php, loaded via require, never a network store).

What it changes

  • Router::cache() / clearCache() now use the file cache driver via a small getRouteCacher() helper, instead of the default (Redis) store. Booting no longer depends on a networked cache.
  • Invalidation is unchanged — the cache key still embeds the route file filemtime, so a new deploy auto-rebuilds on first hit.
  • Tests run against the file store (temp dir + cleanup) to exercise the real path.

No public API change; Route::cache(__FILE__, ...) call sites are untouched.

Route caching resolved the container's default cache store, which in
production is Redis. Because routes are loaded during application boot
(`start.php` -> `routes.php` -> `Route::cache()`), every web request and
artisan command — including `queue:work` — issued a Redis GET at boot.
When Redis was unreachable the whole boot failed with
`Predis\Connection\ConnectionException`.

Route cache is a build-time artifact that is deterministic per release,
so it belongs on local disk, mirroring modern Laravel's file-based route
cache. Pin the store to the "file" driver so booting never depends on a
networked cache. Invalidation is unchanged (cache key already embeds the
route file mtime).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@agissept
agissept merged commit 548fad8 into master Aug 27, 2026
2 checks passed
@agissept
agissept deleted the improvements/local-route-cache branch August 27, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant