diff --git a/frameworks/Rust/axum/src/main_sqlx.rs b/frameworks/Rust/axum/src/main_sqlx.rs index d10b1ea99ef..163372b83d8 100644 --- a/frameworks/Rust/axum/src/main_sqlx.rs +++ b/frameworks/Rust/axum/src/main_sqlx.rs @@ -1,8 +1,6 @@ mod common; mod sqlx; -use std::sync::Arc; - use ::sqlx::PgPool; use axum::{ extract::{Query, State}, @@ -98,7 +96,7 @@ async fn cache( ) -> impl IntoResponse { let count = parse_params(params); let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); - let mut worlds: Vec>> = Vec::with_capacity(count); + let mut worlds: Vec> = Vec::with_capacity(count); for id in random_ids(&mut rng, count) { worlds.push(cache.get(&id).await); @@ -115,14 +113,15 @@ async fn preload_cache(AppState { db, cache }: &AppState) { .expect("error loading worlds"); for world in worlds { - cache.insert(world.id, Arc::new(world)).await; + cache.insert(world.id, world).await; } } +/// Application state #[derive(Clone)] struct AppState { db: PgPool, - cache: Cache>, + cache: Cache, } #[tokio::main] @@ -135,7 +134,10 @@ async fn main() { let state = AppState { db: create_pool(database_url, max_pool_size, min_pool_size).await, - cache: Cache::new(10000), + cache: Cache::builder() + .initial_capacity(10000) + .max_capacity(10000) + .build() }; // Prime the cache with CachedWorld objects