瀏覽代碼

remove logging

Evan Almloff 2 年之前
父節點
當前提交
3d41dd95c9
共有 2 個文件被更改,包括 12 次插入5 次删除
  1. 1 1
      packages/router/examples/static_generation.rs
  2. 11 4
      packages/router/src/ssr.rs

+ 1 - 1
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::<Route>();

+ 11 - 4
packages/router/src/ssr.rs

@@ -132,8 +132,16 @@ impl<R: RenderHTML> IncrementalRenderer<R> {
         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<K: AsRef<str> + 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<R: RenderHTML> IncrementalRenderer<R> {
             .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