Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Laravel Views Cache works?

According to Laravel's documentation (https://laravel.com/docs/5.3/blade#introduction) views are compiled into plain PHP code and cached until they are modified but when are they re-compiled?

I have my project in a production environment and when I deploy changes are automatically showed, I don't need to clear views cache or something similar.

Are views re-compiled automatically (in that case, when does it happen?) or do I haven't cache enabled?

like image 289
Alan Avatar asked Aug 29 '16 15:08

Alan


People also ask

Does Laravel view cache?

When a request is executed that renders a view, Laravel will compile the view if a pre-compiled view does not already exist (or if the view has been modified more recently than the compiled view). View caching pre-compiles all of the views utilized by your application.

How cache is implemented in Laravel?

To enable Laravel caching services, first use the Illuminate\Contracts\Cache\Factory and Illuminate\Contracts\Cache\Repository, as they provide access to the Laravel caching services. The Factory contract gives access to all the cache drivers of your application.

How does Redis cache work Laravel?

Laravel supports the use of Redis, which uses caches for temporary data storage to speed up the process of performing database queries and getting feedback, which will, in turn, reduce the amount of time spent pulling up data.

How does php cache work?

A cache is a collection of duplicate data, where the original data is expensive to fetch or compute (usually in terms of access time) relative to the cache. In PHP, caching is used to minimize page generation time.


1 Answers

By default all views are compiled/cached. You can define a path where to store compiled version in app/config/view.php. When Laravel framework tries to compile a view it check the modification date of the source view file and compiled version if the last one exists. If the compiled file is older than a the source file Laravel recompiled the view and store it as a new cached version of the source file. It happens every time when you deploy a new version of the code.

like image 192
Andrej Ludinovskov Avatar answered Oct 06 '22 09:10

Andrej Ludinovskov