1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! ## Cache hydration
//!
//! This module provides functionality to hydrate the application's shared cache with JSON data.
//! It includes a function to insert JSON data into the cache and return the same data.
use crateAppState;
use Data;
use Value;
// no-op: keep imports minimal here
use crateGLOBAL_REDIS;
/// Hydrates the cache with the provided JSON body and returns the JSON body.
///
/// # Arguments
///
/// * `app_state` - A `Data<AppState>` representing the shared application state with caches.
/// * `cache_key` - A `String` that serves as the key for storing the JSON body in the cache.
/// * `json_body` - A `Vec<Value>` containing the JSON data to be cached.
///
/// # Returns
///
/// * `Vec<Value>` - The same JSON body that was provided as input.
///
/// # Example
///
/// ```rust,no_run
/// # use actix_web::web::Data;
/// # use athena_rs::api::cache::hydrate::hydrate_cache_and_return_json;
/// # use athena_rs::AppState;
/// # use athena_rs::drivers::postgresql::sqlx_driver::PostgresClientRegistry;
/// # use moka::future::Cache;
/// # use reqwest::Client;
/// # use serde_json::json;
/// # use std::sync::Arc;
/// # use std::time::Instant;
/// # async fn doc_example() {
/// # let cache: Cache<String, serde_json::Value> = Cache::builder().build();
/// # let immortal: Cache<String, serde_json::Value> = Cache::builder().build();
/// # let jdbc_pool_cache = Arc::new(Cache::builder().max_capacity(64).build());
/// # let app_state = AppState {
/// # cache: Arc::new(cache),
/// # immortal_cache: Arc::new(immortal),
/// # client: Client::new(),
/// # process_start_time_seconds: 0,
/// # process_started_at: Instant::now(),
/// # pg_registry: Arc::new(PostgresClientRegistry::empty()),
/// # jdbc_pool_cache,
/// # gateway_force_camel_case_to_snake_case: false,
/// # gateway_auto_cast_uuid_filter_values_to_text: true,
/// # gateway_allow_schema_names_prefixed_as_table_name: true,
/// # pipeline_registry: None,
/// # logging_client_name: None,
/// # gateway_auth_client_name: None,
/// # gateway_jdbc_allow_private_hosts: false,
/// # gateway_jdbc_allowed_hosts: Vec::new(),
/// # gateway_resilience_timeout_secs: 30,
/// # gateway_resilience_read_max_retries: 1,
/// # gateway_resilience_initial_backoff_ms: 100,
/// # prometheus_metrics_enabled: false,
/// # metrics_state: Arc::new(athena_rs::api::metrics::MetricsState::new()),
/// # };
/// # let app_state = Data::new(app_state);
/// let cache_key = String::from("my_cache_key");
/// let json_body = vec![json!(1), json!(2), json!(3)];
/// let result = hydrate_cache_and_return_json(app_state, cache_key, json_body).await;
/// assert_eq!(result, vec![json!(1), json!(2), json!(3)]);
/// # }
/// ```
pub async