athena_rs 2.12.1

Database gateway API
Documentation
use crate::AppState;
use actix_web::web::Data;

/// Invalidates only cache keys related to a specific client/table/query family.
///
/// Current strategy:
/// - table-scoped gateway fetch keys start with `<table_name>:`
/// - query-count family keys use `query_count:`
/// - raw fast-path variants use `:__raw_json`
pub async fn invalidate_scoped_gateway_cache(
    app_state: Data<AppState>,
    client_name: &str,
    table_name: &str,
) -> usize {
    let table_prefix = format!("{}:", table_name.trim());
    let normalized_client = client_name.trim().to_ascii_lowercase();

    let _ = app_state.cache.invalidate_entries_if({
        move |key, _value| {
            let key = key.as_str();
            key.starts_with(&table_prefix)
                || key.starts_with("query_count:")
                || key.ends_with(":__raw_json")
                || key.to_ascii_lowercase().contains(&normalized_client)
        }
    });

    app_state.cache.run_pending_tasks().await;
    app_state.cache.entry_count() as usize
}