Skip to content

Commit

Permalink
Refine Leaf cache documentation (#1053)
Browse files Browse the repository at this point in the history
Added an improvement for the cache documentation, as discussed at
#850 (comment).

Co-authored-by: Tim Condon <[email protected]>
  • Loading branch information
alemohamad and 0xTim authored Jan 17, 2025
1 parent 4a377cf commit 4e68a52
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions docs/leaf/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4e68a52

Please sign in to comment.