mirror of https://github.com/vapor/docs.git
Refine Leaf cache documentation (#1053)
Added an improvement for the cache documentation, as discussed at https://github.com/vapor/docs/issues/850#issuecomment-1621691102. Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
This commit is contained in:
parent
4a377cfabb
commit
4e68a524cb
|
|
@ -41,11 +41,22 @@ app.views.use(.leaf)
|
||||||
|
|
||||||
This tells Vapor to use the `LeafRenderer` when you call `req.view` in your code.
|
This tells Vapor to use the `LeafRenderer` when you call `req.view` in your code.
|
||||||
|
|
||||||
!!! note
|
|
||||||
Leaf has an internal cache for rendering pages. When the `Application`'s environment is set to `.development`, this cache is disabled, so that changes to templates take effect immediately. In `.production` and all other environments, the cache is enabled by default; any changes made to templates will not take effect until the application is restarted.
|
|
||||||
|
|
||||||
!!! warning
|
!!! warning
|
||||||
For Leaf to be able to find the templates when running from Xcode, you must set the [custom working directory](../getting-started/xcode.md#custom-working-directory) for you Xcode workspace.
|
For Leaf to be able to find the templates when running from Xcode, you must set the [custom working directory](../getting-started/xcode.md#custom-working-directory) for you Xcode workspace.
|
||||||
|
|
||||||
|
### Cache for Rendering Pages
|
||||||
|
|
||||||
|
Leaf has an internal cache for rendering pages. When the `Application`'s environment is set to `.development`, this cache is disabled, so that changes to templates take effect immediately. In `.production` and all other environments, the cache is enabled by default. Any changes made to templates will not take effect until the application is restarted.
|
||||||
|
|
||||||
|
To disable Leaf's cache do the following:
|
||||||
|
|
||||||
|
```swift
|
||||||
|
app.leaf.cache.isEnabled = false
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! warning
|
||||||
|
While disabling cache is helpful for debugging, it's not recommended for production environments as it can significantly impact performance due to the need to recompile templates on every request.
|
||||||
|
|
||||||
## Folder Structure
|
## Folder Structure
|
||||||
|
|
||||||
Once you have configured Leaf, you will need to ensure you have a `Views` folder to store your `.leaf` files in. By default, Leaf expects the views folder to be a `./Resources/Views` relative to your project's root.
|
Once you have configured Leaf, you will need to ensure you have a `Views` folder to store your `.leaf` files in. By default, Leaf expects the views folder to be a `./Resources/Views` relative to your project's root.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue