From cbf2629bebf1d7147c888a154193374e8af994b3 Mon Sep 17 00:00:00 2001 From: arctic_hen7 Date: Thu, 17 Feb 2022 20:03:05 +1100 Subject: [PATCH] refactor: restructured logic revalidation example to show types clearly --- .../core/state_generation/src/templates/revalidation.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/core/state_generation/src/templates/revalidation.rs b/examples/core/state_generation/src/templates/revalidation.rs index 52be42a6fd..c973df9720 100644 --- a/examples/core/state_generation/src/templates/revalidation.rs +++ b/examples/core/state_generation/src/templates/revalidation.rs @@ -22,7 +22,7 @@ pub fn get_template() -> Template { // load this page. For that reason, this should NOT do long-running work, as requests will be delayed. If both this // and `revaldiate_after()` are provided, this logic will only run when `revalidate_after()` tells Perseus // that it should revalidate. - .should_revalidate_fn(|| async { Ok(true) }) + .should_revalidate_fn(should_revalidate) .build_state_fn(get_build_state) } @@ -33,3 +33,10 @@ pub async fn get_build_state(_path: String, _locale: String) -> RenderFnResultWi time: format!("{:?}", std::time::SystemTime::now()), }) } + +// This will run every time `.revalidate_after()` permits the page to be revalidated +// This acts as a secondary check, and can perform arbitrary logic to check if we should actually revalidate a page +pub async fn should_revalidate() -> RenderFnResultWithCause { + // For simplicity's sake, this will always say we should revalidate, but you could amke this check any condition + Ok(true) +}