From 3d41dd95c97040f325a1275dfcbb41f06a765e2e Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 21 Jun 2023 18:51:40 -0700 Subject: [PATCH] remove logging --- packages/router/examples/static_generation.rs | 2 +- packages/router/src/ssr.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/router/examples/static_generation.rs b/packages/router/examples/static_generation.rs index f678080c6..00c08e0fa 100644 --- a/packages/router/examples/static_generation.rs +++ b/packages/router/examples/static_generation.rs @@ -2,6 +2,7 @@ use dioxus::prelude::*; use dioxus_router::prelude::*; + use dioxus_router::ssr::{DefaultRenderer, IncrementalRendererConfig}; fn main() { @@ -21,7 +22,6 @@ fn main() { .to_string(), }) .static_dir("./static") - .memory_cache_limit(5) .build(); renderer.pre_cache_static::(); diff --git a/packages/router/src/ssr.rs b/packages/router/src/ssr.rs index eb9ad648b..f72f4ec6e 100644 --- a/packages/router/src/ssr.rs +++ b/packages/router/src/ssr.rs @@ -132,8 +132,16 @@ impl IncrementalRenderer { let file = std::fs::File::create(dbg!(file_path)).unwrap(); let mut file = std::io::BufWriter::new(file); file.write_all(html.as_bytes()).unwrap(); + self.add_to_memory_cache(route, html); + } + + fn add_to_memory_cache + ToString, V: ToString>(&mut self, route: K, html: V) { if let Some(cache) = self.memory_cache.as_mut() { - cache.put(route, html); + if cache.contains(route.as_ref()) { + cache.promote(route.as_ref()) + } else { + cache.put(route.to_string(), html.to_string()); + } } } @@ -143,15 +151,14 @@ impl IncrementalRenderer { .as_mut() .and_then(|cache| cache.get(&route).cloned()) { - println!("memory cache hit"); Some(cache_hit) } else { let file_path = self.route_as_path(&route); - if let Ok(file) = dbg!(std::fs::File::open(file_path)) { + if let Ok(file) = std::fs::File::open(file_path) { let mut file = std::io::BufReader::new(file); let mut html = String::new(); file.read_to_string(&mut html).ok()?; - println!("file cache hit"); + self.add_to_memory_cache(route, html.clone()); Some(html) } else { None