From 4e68a524cb881efe5dd8b7a6d140c28ea314d0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=20Mohamad=20=E2=8C=98?= Date: Fri, 17 Jan 2025 21:13:34 +0100 Subject: [PATCH] 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> --- docs/leaf/getting-started.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/leaf/getting-started.md b/docs/leaf/getting-started.md index b494fc89..7013d190 100644 --- a/docs/leaf/getting-started.md +++ b/docs/leaf/getting-started.md @@ -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.