From 525f6d4a34fc7c25d4e14133bcd3baa4453cc223 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 16 May 2023 14:58:00 -0700 Subject: [PATCH] better variable names --- web3_proxy/src/frontend/mod.rs | 17 +++++++---------- web3_proxy/src/frontend/status.rs | 19 +++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/web3_proxy/src/frontend/mod.rs b/web3_proxy/src/frontend/mod.rs index b5ebbbe5..aa827909 100644 --- a/web3_proxy/src/frontend/mod.rs +++ b/web3_proxy/src/frontend/mod.rs @@ -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); diff --git a/web3_proxy/src/frontend/status.rs b/web3_proxy/src/frontend/status.rs index a23b0a70..afa9ebb0 100644 --- a/web3_proxy/src/frontend/status.rs +++ b/web3_proxy/src/frontend/status.rs @@ -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 = Lazy::new(|| Bytes::from("false\n")); #[debug_handler] pub async fn health( Extension(app): Extension>, - Extension(cache): Extension>, + Extension(cache): Extension>, ) -> impl IntoResponse { cache - .get_or_insert_async::(&FrontendResponseCacheKey::Health, async move { + .get_or_insert_async::(&ResponseCacheKey::Health, async move { Ok(_health(app).await) }) .await @@ -44,13 +44,12 @@ async fn _health(app: Arc) -> (StatusCode, Bytes) { #[debug_handler] pub async fn backups_needed( Extension(app): Extension>, - Extension(cache): Extension>, + Extension(cache): Extension>, ) -> impl IntoResponse { cache - .get_or_insert_async::( - &FrontendResponseCacheKey::BackupsNeeded, - async move { Ok(_backups_needed(app).await) }, - ) + .get_or_insert_async::(&ResponseCacheKey::BackupsNeeded, async move { + Ok(_backups_needed(app).await) + }) .await } @@ -88,10 +87,10 @@ async fn _backups_needed(app: Arc) -> (StatusCode, Bytes) { #[debug_handler] pub async fn status( Extension(app): Extension>, - Extension(cache): Extension>, + Extension(cache): Extension>, ) -> impl IntoResponse { cache - .get_or_insert_async::(&FrontendResponseCacheKey::Status, async move { + .get_or_insert_async::(&ResponseCacheKey::Status, async move { Ok(_status(app).await) }) .await