Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stefr's avatar
Level 9

Route-, config- and view cache in Vapor

I have a question about deployment optimization for Vapor. In the laravel docs (https://laravel.com/docs/master/deployment#optimization) we’re encouraged to cache routes, config and views (php artisan route:cache etc.).

There is no mention about this in the Vapor docs. How do we do this in Vapor? Or don’t we need this in Vapor?

0 likes
10 replies
bobbybouwmann's avatar
Level 88

You don't have to do this at all. Vapor is handling all of this for you.

For example, caching your config won't make sense since Vapor controls your environment variables. If you cache your config, the env variables won't be loaded anymore. Either this is not done, or automatically done by Vapor.

For route caching and view caching I'm not sure. I expect that Vapor is doing this automatically for you on each deployment.

If you want to control your caches I would highly recommend storing it in Redis for example. This way you can still get access or clear it by yourself without having to deploy on Vapor.

3 likes
dniccum's avatar

I am 95% certain that Vapor is NOT caching routes or the configuration files as part of a deployment. I know this because I had 4 or 5 routes that were defined as closures. In the documentation it is said that all routes must be defined using classes. If you try to cache your routes while using closures the process will throw a fatal error.

tdondich's avatar

Just to be clear, Laravel Vapor will cache your config. It will not cache your routes, events or views. You can see the config:cache command in your Lambda logs being called. It will say 'Caching laravel configuration'. You can find this code in the fpmRuntime.php and cliRuntime and octaneRuntime.php files in the vapor-core repo.

1 like
alejandrozepeda's avatar

hi @tdondich do you know in which part of the documentation said that it will not cache your routes, events, or views? thanks

Benja's avatar

@tdondich Laravel Vapor definitely caches your views, i just got the following error on sentry from a laravel app deployed on vapor

ErrorException
file_put_contents(/tmp/storage/framework/views/0cc064f972e8cd9c26b16f5f0b641765.php): Failed to open stream: No space left on device
halilcosdu's avatar

Example : you may use like this in vapor.yml

    build:
        - 'COMPOSER_MIRROR_PATH_REPOS=1 composer install --no-dev'
        - 'php artisan optimize'
        - 'php artisan event:cache'
        - 'php artisan icons:cache'
        - 'php artisan queue:restart'
        - 'npm ci && npm run build && rm -rf node_modules'
    deploy:
      - 'php artisan migrate --force'
martijnDB's avatar

These commands will not work during the build step: 'clear-compiled', 'optimize:clear', 'route:cache',

Since 10 months ago. See: https://github.com/laravel/vapor-cli/actions/runs/5134349278

<?php

namespace Laravel\VaporCli\BuildProcess;

use Illuminate\Support\Str;
use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Manifest;
use Symfony\Component\Process\Process;

class ExecuteBuildCommands
{
    use ParticipatesInBuildProcess;

    /**
     * @var array<int, string>
     */
    protected $unsupportedCommands = [
        'clear-compiled',
        'optimize:clear',
        'route:cache',
    ];
2 likes
Raymond7905-36502477's avatar

I’ve added config:cache to my deploy hook and I have, without exaggeration, noticed a substantial performance increase. Each request is much snappier responding.

Please or to participate in this conversation.