Skip to content

Commit

Permalink
refactor: use Clone instead of Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Oct 23, 2024
1 parent 0981e1f commit d687b41
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ struct ApiSpecification;

pub fn app(max_cache_memory: u64, cache_expiry: std::time::Duration) -> Router {
let root_path = "/api";
let shared_state = std::sync::Arc::new(state::AppState {
let shared_state = state::AppState {
cache: moka::future::Cache::builder()
.weigher(|_, v: &Vec<u8>| v.len().try_into().unwrap_or(u32::MAX))
.max_capacity(max_cache_memory)
.time_to_idle(cache_expiry)
.build_with_hasher(gxhash::GxBuildHasher::default()),
});
};

Router::new()
.nest(
Expand Down
1 change: 1 addition & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use gxhash::GxBuildHasher;

#[derive(Clone)]
pub struct AppState {
pub cache: moka::future::Cache<String, Vec<u8>, GxBuildHasher>,
}
2 changes: 1 addition & 1 deletion src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use axum::{

use crate::state::AppState;

pub fn router(shared_state: std::sync::Arc<AppState>) -> Router {
pub fn router(shared_state: AppState) -> Router {
Router::new()
.route("/v1", get(index::index))
.route("/v1/compile", post(compile::compile))
Expand Down
4 changes: 1 addition & 3 deletions src/v1/compile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use axum::body::Body;
use axum::extract::State;
use axum::http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
Expand All @@ -25,7 +23,7 @@ pub struct CompileSchema {
)
)]
pub async fn compile(
State(state): State<Arc<AppState>>,
State(state): State<AppState>,
Json(payload): Json<CompileSchema>,
) -> impl IntoResponse {
let result = state
Expand Down

0 comments on commit d687b41

Please sign in to comment.