logo
podcast Podcast
get help Get Unstuck

Should you run `optimize` with Vapor?

I didn't see this in the docs

Joel Clermont
Joel Clermont
2024-10-01

Recently, I was working with a client and they asked me about which caching commands should be run on Vapor? Was it safe to run the typical php artisan optimize command, which caches configs, events, routes, and views?

The docs didn't say anything explicitly about this. Even more telling, the few examples that showed a caching command in the build step only listed event:cache, nothing else.

So I decided to do a little bit of digging. One thing I saw in the Vapor CLI repo is that certain commands are prohibited. One of those is route:cache.

Why is route caching not supported? Route serialization involves using the app.key, and this value is going to likely be different on your build machine (local or CI) as compared to the production environment.

What about the other cache commands? Well, I can only dig so far into Vapor through open source. Some of it is not public, so I asked support.

Here was the reply I got:

We also run config:cache and view:cache every time a container boots. So we typically recommend event to be the only cache option to be run at deploy time in the build hook.

Problem solved, event:cache really is the only command you need to run on build when using Vapor.

Here to help,

Joel

P.S. Are you stuck on a problem and need someone tenacious like me to figure it out?

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.