Skip to content

Commit

Permalink
refactor: restructured logic revalidation example to show types clearly
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Feb 17, 2022
1 parent e565632 commit cbf2629
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/core/state_generation/src/templates/revalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn get_template<G: Html>() -> Template<G> {
// 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)
}

Expand All @@ -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<bool> {
// For simplicity's sake, this will always say we should revalidate, but you could amke this check any condition
Ok(true)
}

0 comments on commit cbf2629

Please sign in to comment.