async fn should_revalidate(
    template: &Template<SsrNode>,
    path_encoded: &str,
    mutable_store: &impl MutableStore,
) -> Result<bool, ServerError> {
    let mut should_revalidate = false;
    // If it revalidates after a certain period of time, we needd to check that BEFORE the custom logic
    if template.revalidates_with_time() {
        // Get the time when it should revalidate (RFC 3339)
        // This will be updated, so it's in a mutable store
        let datetime_to_revalidate_str = mutable_store
            .read(&format!("static/{}.revld.txt", path_encoded))
            .await?;
        let datetime_to_revalidate = DateTime::parse_from_rfc3339(&datetime_to_revalidate_str)
            .map_err(|e| {
                let serve_err: ServeError = e.into();
                serve_err
            })?;
        // Get the current time (UTC)
        let now = Utc::now();

        // If the datetime to revalidate is still in the future, end with `false`
        if datetime_to_revalidate > now {
            return Ok(false);
        }
        should_revalidate = true;
    }

    // Now run the user's custom revalidation logic
    if template.revalidates_with_logic() {
        should_revalidate = template.should_revalidate().await?;
    }
    Ok(should_revalidate)
}
/// Checks if a template should revalidate by time. All revalidation timestamps are stored in a mutable store, so that's what this
/// function uses.
Checks if a template should revalidate by time. All revalidation timestamps are stored in a mutable store, so that's what this
function uses.
Checks if a template should revalidate by time . All revalidation timestamps are stored in a mutable store so that ' s what this function uses .
async fn should_revalidate(
    template: &Template<SsrNode>,
    path_encoded: &str,
    mutable_store: &impl MutableStore,
) -> Result<bool, ServerError> {
    let mut should_revalidate = false;
    // If it revalidates after a certain period of time, we needd to check that BEFORE the custom logic
    if template.revalidates_with_time() {
        // Get the time when it should revalidate (RFC 3339)
        // This will be updated, so it's in a mutable store
        let datetime_to_revalidate_str = mutable_store
            .read(&format!("static/{}.revld.txt", path_encoded))
            .await?;
        let datetime_to_revalidate = DateTime::parse_from_rfc3339(&datetime_to_revalidate_str)
            .map_err(|e| {
                let serve_err: ServeError = e.into();
                serve_err
            })?;
        // Get the current time (UTC)
        let now = Utc::now();
        // If the datetime to revalidate is still in the future, end with `false`
        if datetime_to_revalidate > now {
            return Ok(false);
        }
        should_revalidate = true;
    }
    // Now run the user's custom revalidation logic
    if template.revalidates_with_logic() {
        should_revalidate = template.should_revalidate().await?;
    }
    Ok(should_revalidate)
}
async fn should_revalidate ( template : & Template < SsrNode > , path_encoded : & str , mutable_store : & impl MutableStore , ) -> Result < bool , ServerError > { let mut should_revalidate = false ; // If it revalidates after a certain period of time, we needd to check that BEFORE the custom logic if template . revalidates_with_time ( ) { // Get the time when it should revalidate (RFC 3339) // This will be updated, so it's in a mutable store let datetime_to_revalidate_str = mutable_store . read ( & format ! ( " " path_encoded ) ) . await ? ; let datetime_to_revalidate = DateTime :: parse_from_rfc3339 ( & datetime_to_revalidate_str ) . map_err ( | e | { let serve_err : ServeError = e . into ( ) ; serve_err } ) ? ; // Get the current time (UTC) let now = Utc :: now ( ) ; // If the datetime to revalidate is still in the future, end with `false` if datetime_to_revalidate > now { return Ok ( false ) ; } should_revalidate = true ; } // Now run the user's custom revalidation logic if template . revalidates_with_logic ( ) { should_revalidate = template . should_revalidate ( ) . await ? ; } Ok ( should_revalidate ) }
Checks if a template should revalidate by time.
Checks if a template should revalidate by time .
template
&Template<SsrNode>
path_encoded
&str
mutable_store
&impl MutableStore
template
&Template<SsrNode>
path_encoded
&str
mutable_store
&impl MutableStore