better variable names
This commit is contained in:
parent
40b15579ab
commit
525f6d4a34
@ -30,14 +30,14 @@ use tower_http::sensitive_headers::SetSensitiveRequestHeadersLayer;
|
||||
|
||||
/// simple keys for caching responses
|
||||
#[derive(Copy, Clone, Hash, PartialEq, Eq, EnumCount, EnumIter)]
|
||||
pub enum FrontendResponseCacheKey {
|
||||
pub enum ResponseCacheKey {
|
||||
BackupsNeeded,
|
||||
Health,
|
||||
Status,
|
||||
}
|
||||
|
||||
pub type FrontendJsonResponseCache = quick_cache_ttl::CacheWithTTL<
|
||||
FrontendResponseCacheKey,
|
||||
pub type ResponseCache = quick_cache_ttl::CacheWithTTL<
|
||||
ResponseCacheKey,
|
||||
(StatusCode, axum::body::Bytes),
|
||||
UnitWeighter,
|
||||
quick_cache_ttl::DefaultHashBuilder,
|
||||
@ -53,13 +53,10 @@ pub async fn serve(
|
||||
// setup caches for whatever the frontend needs
|
||||
// no need for max items since it is limited by the enum key
|
||||
// TODO: latest moka allows for different ttls for different
|
||||
let response_cache_size = FrontendResponseCacheKey::COUNT;
|
||||
let response_cache_size = ResponseCacheKey::COUNT;
|
||||
|
||||
let json_response_cache = FrontendJsonResponseCache::new_with_unit_weights(
|
||||
response_cache_size,
|
||||
Duration::from_secs(1),
|
||||
)
|
||||
.await;
|
||||
let response_cache =
|
||||
ResponseCache::new_with_unit_weights(response_cache_size, Duration::from_secs(1)).await;
|
||||
|
||||
// TODO: read config for if fastest/versus should be available publicly. default off
|
||||
|
||||
@ -225,7 +222,7 @@ pub async fn serve(
|
||||
// application state
|
||||
.layer(Extension(proxy_app))
|
||||
// frontend caches
|
||||
.layer(Extension(Arc::new(json_response_cache)))
|
||||
.layer(Extension(Arc::new(response_cache)))
|
||||
// 404 for any unknown routes
|
||||
.fallback(errors::handler_404);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! For ease of development, users can currently access these endponts.
|
||||
//! They will eventually move to another port.
|
||||
|
||||
use super::{FrontendJsonResponseCache, FrontendResponseCacheKey};
|
||||
use super::{ResponseCache, ResponseCacheKey};
|
||||
use crate::app::{Web3ProxyApp, APP_USER_AGENT};
|
||||
use axum::{body::Bytes, http::StatusCode, response::IntoResponse, Extension};
|
||||
use axum_macros::debug_handler;
|
||||
@ -21,10 +21,10 @@ static BACKUPS_NEEDED_FALSE: Lazy<Bytes> = Lazy::new(|| Bytes::from("false\n"));
|
||||
#[debug_handler]
|
||||
pub async fn health(
|
||||
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
||||
Extension(cache): Extension<Arc<FrontendJsonResponseCache>>,
|
||||
Extension(cache): Extension<Arc<ResponseCache>>,
|
||||
) -> impl IntoResponse {
|
||||
cache
|
||||
.get_or_insert_async::<Infallible, _>(&FrontendResponseCacheKey::Health, async move {
|
||||
.get_or_insert_async::<Infallible, _>(&ResponseCacheKey::Health, async move {
|
||||
Ok(_health(app).await)
|
||||
})
|
||||
.await
|
||||
@ -44,13 +44,12 @@ async fn _health(app: Arc<Web3ProxyApp>) -> (StatusCode, Bytes) {
|
||||
#[debug_handler]
|
||||
pub async fn backups_needed(
|
||||
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
||||
Extension(cache): Extension<Arc<FrontendJsonResponseCache>>,
|
||||
Extension(cache): Extension<Arc<ResponseCache>>,
|
||||
) -> impl IntoResponse {
|
||||
cache
|
||||
.get_or_insert_async::<Infallible, _>(
|
||||
&FrontendResponseCacheKey::BackupsNeeded,
|
||||
async move { Ok(_backups_needed(app).await) },
|
||||
)
|
||||
.get_or_insert_async::<Infallible, _>(&ResponseCacheKey::BackupsNeeded, async move {
|
||||
Ok(_backups_needed(app).await)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
@ -88,10 +87,10 @@ async fn _backups_needed(app: Arc<Web3ProxyApp>) -> (StatusCode, Bytes) {
|
||||
#[debug_handler]
|
||||
pub async fn status(
|
||||
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
||||
Extension(cache): Extension<Arc<FrontendJsonResponseCache>>,
|
||||
Extension(cache): Extension<Arc<ResponseCache>>,
|
||||
) -> impl IntoResponse {
|
||||
cache
|
||||
.get_or_insert_async::<Infallible, _>(&FrontendResponseCacheKey::Status, async move {
|
||||
.get_or_insert_async::<Infallible, _>(&ResponseCacheKey::Status, async move {
|
||||
Ok(_status(app).await)
|
||||
})
|
||||
.await
|
||||
|
Loading…
Reference in New Issue
Block a user