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:
Ale Mohamad ⌘ 2025-01-17 21:13:34 +01:00 committed by GitHub
parent 4a377cfabb
commit 4e68a524cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 3 deletions

View File

@ -41,11 +41,22 @@ app.views.use(.leaf)
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
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
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.