Skip to content

[9.x] Add option to disable cached view#41859

Merged
taylorotwell merged 3 commits intolaravel:9.xfrom
bernardwiesner:disable-cached-view-option
Apr 7, 2022
Merged

[9.x] Add option to disable cached view#41859
taylorotwell merged 3 commits intolaravel:9.xfrom
bernardwiesner:disable-cached-view-option

Conversation

@bernardwiesner
Copy link
Copy Markdown
Contributor

@bernardwiesner bernardwiesner commented Apr 7, 2022

Especially during development its very helpful to disable the cached views. Here are a few use cases:

  • Switching domains on local from 127.0.0.1 to local-your-domain.com on local (such as when using ssl certificates)
    When switching domains the same compiled view is returned using the old domain in JS, CSS, etc.

  • Custom implementation that add modify contents on compile time, such as custom cache busters for JS.
    Adding a query string to JS for cache busting done with PHP at compile time.

And many other use cases where view caching might not be desirable on local.

Relates to: #2501

Would enable inside config/view.php using

'cache' => App::environment('local') ? false : true

@taylorotwell taylorotwell merged commit bb9a897 into laravel:9.x Apr 7, 2022
@xxdalexx
Copy link
Copy Markdown

xxdalexx commented Apr 27, 2022

This comes with a big caveat of test speed.
For the project I tried this on, running the full suite not in parallel:
With View Caching: 4.8 Seconds
Without: 1 Minute, 19 Seconds

A work around is to point your config to a .env variable to disable view caching for local serving, and enabling it in the phpunit.xml for testing.

@bernardwiesner
Copy link
Copy Markdown
Contributor Author

@xxdalexx
Thanks for pointing out, however I think most folks won't have an issue since by default phpunit.xml is already set to testing environment.
https://github.com/laravel/laravel/blob/d0603437cbbb478586979a3792d49e0d157ce554/phpunit.xml#L21

@joelmellon
Copy link
Copy Markdown
Contributor

@bernardwiesner Thanks! Great feature.

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.

4 participants