Clear the cache on rebuild in the incremental renderer (#1741)
This commit is contained in:
1 parent
937be8b752
commit
43d9fe1ab0
1 file changed
+15
-1
@@ -67,6 +67,7 @@ pub struct IncrementalRendererConfig {
|
|||||||
memory_cache_limit: usize,
|
memory_cache_limit: usize,
|
||||||
invalidate_after: Option<Duration>,
|
invalidate_after: Option<Duration>,
|
||||||
map_path: Option<PathMapFn>,
|
map_path: Option<PathMapFn>,
|
||||||
|
clear_cache: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for IncrementalRendererConfig {
|
impl Default for IncrementalRendererConfig {
|
||||||
@@ -83,9 +84,16 @@ impl IncrementalRendererConfig {
|
|||||||
memory_cache_limit: 10000,
|
memory_cache_limit: 10000,
|
||||||
invalidate_after: None,
|
invalidate_after: None,
|
||||||
map_path: None,
|
map_path: None,
|
||||||
|
clear_cache: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clear the cache on startup (default: true)
|
||||||
|
pub fn clear_cache(mut self, clear_cache: bool) -> Self {
|
||||||
|
self.clear_cache = clear_cache;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set a mapping from the route to the file path. This will override the default mapping configured with `static_dir`.
|
/// Set a mapping from the route to the file path. This will override the default mapping configured with `static_dir`.
|
||||||
/// The function should return the path to the folder to store the index.html file in.
|
/// The function should return the path to the folder to store the index.html file in.
|
||||||
pub fn map_path<F: Fn(&str) -> PathBuf + Send + Sync + 'static>(mut self, map_path: F) -> Self {
|
pub fn map_path<F: Fn(&str) -> PathBuf + Send + Sync + 'static>(mut self, map_path: F) -> Self {
|
||||||
@@ -114,7 +122,7 @@ impl IncrementalRendererConfig {
|
|||||||
/// Build the incremental renderer.
|
/// Build the incremental renderer.
|
||||||
pub fn build(self) -> IncrementalRenderer {
|
pub fn build(self) -> IncrementalRenderer {
|
||||||
let static_dir = self.static_dir.clone();
|
let static_dir = self.static_dir.clone();
|
||||||
IncrementalRenderer {
|
let mut renderer = IncrementalRenderer {
|
||||||
static_dir: self.static_dir.clone(),
|
static_dir: self.static_dir.clone(),
|
||||||
memory_cache: NonZeroUsize::new(self.memory_cache_limit)
|
memory_cache: NonZeroUsize::new(self.memory_cache_limit)
|
||||||
.map(|limit| lru::LruCache::with_hasher(limit, Default::default())),
|
.map(|limit| lru::LruCache::with_hasher(limit, Default::default())),
|
||||||
@@ -129,6 +137,12 @@ impl IncrementalRendererConfig {
|
|||||||
path
|
path
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
if self.clear_cache {
|
||||||
|
renderer.invalidate_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user