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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//! Cache Check Module
//!
//! This module provides functionality to check and retrieve cached responses based on cache control headers.
use crateAppState;
use crateGLOBAL_REDIS;
use ;
use ;
/// ## Get Cached Response
///
/// This function retrieves a cached response for a given cache key.
///
/// ### Parameters
///
/// - `app_state`: A `Data<AppState>` instance containing the shared cache.
/// - `cache_key`: A string slice representing the key to look up in the cache.
///
/// ### Returns
///
/// - `Option<HttpResponse>`: Returns an `HttpResponse` containing the cached data if found, otherwise `None`.
///
/// ### Example
///
/// ```rust,no_run
/// # use actix_web::web::Data;
/// # use athena_rs::api::cache::check::get_cached_response;
/// # 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::builder().build();
/// # let immortal = 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(),
/// # prometheus_metrics_enabled: false,
/// # metrics_state: Arc::new(athena_rs::api::metrics::MetricsState::new()),
/// # };
/// # let cache = Data::new(app_state);
/// let response = get_cached_response(cache, "some_cache_key").await;
/// # let _ = response;
/// # }
/// ```
pub async
/// ## Check Cache Control and Get Response
///
/// This function checks if the "Cache-Control" header is set to "no-cache" and retrieves the cached response if not.
///
/// ### Parameters
///
/// - `req`: A reference to the `HttpRequest` object.
/// - `app_state`: A `Data<AppState>` instance containing the shared cache.
/// - `cache_key`: A string slice representing the key to look up in the cache.
///
/// ### Returns
///
/// - `Option<HttpResponse>`: Returns an `HttpResponse` containing the cached data if found and cache control is not "no-cache", otherwise `None`.
///
/// ### Example
///
/// ```rust,no_run
/// # use actix_web::http::header::CACHE_CONTROL;
/// # use actix_web::test::TestRequest;
/// # use actix_web::web::Data;
/// # use athena_rs::api::cache::check::check_cache_control_and_get_response;
/// # 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::builder().build();
/// # let immortal = 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(),
/// # prometheus_metrics_enabled: false,
/// # metrics_state: Arc::new(athena_rs::api::metrics::MetricsState::new()),
/// # };
/// # let cache = Data::new(app_state);
/// # let req = TestRequest::default()
/// # .insert_header((CACHE_CONTROL, "max-age=0"))
/// # .to_http_request();
/// let response = check_cache_control_and_get_response(&req, cache, "some_cache_key").await;
/// # let _ = response;
/// # }
/// ```
pub async
/// ## Check Cache Control and Get Response V2
///
/// This function checks if the "Cache-Control" header is set to "no-cache" and retrieves the cached response if not.
///
/// ### Parameters
///
pub async