aboutsummaryrefslogtreecommitdiff
path: root/src/route.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/route.rs')
-rw-r--r--src/route.rs39
1 files changed, 1 insertions, 38 deletions
diff --git a/src/route.rs b/src/route.rs
index a983374..8d7695d 100644
--- a/src/route.rs
+++ b/src/route.rs
@@ -22,9 +22,6 @@ use std::{
sync::{LazyLock, Mutex},
};
-use tokio::time::Instant;
-use windmark::context::RouteContext;
-
#[cfg(debug_assertions)]
pub const CACHE_RATE: u64 = 1;
#[cfg(not(debug_assertions))]
@@ -61,44 +58,10 @@ pub fn track_mount<F, R>(
description: &str,
handler: F,
) where
- F: FnMut(RouteContext) -> R + Send + Sync + 'static,
+ F: FnMut(windmark::context::RouteContext) -> R + Send + Sync + 'static,
R: IntoFuture<Output = windmark::response::Response> + Send + 'static,
<R as IntoFuture>::IntoFuture: Send,
{
(*ROUTES.lock().unwrap()).insert(route.to_string(), Route::new(description));
router.mount(route, handler);
}
-
-pub fn cache(context: &RouteContext, response: &str) {
- static LAST_CACHED: LazyLock<Mutex<Instant>> =
- LazyLock::new(|| Mutex::new(Instant::now()));
-
- if (*LAST_CACHED.lock().unwrap()).elapsed()
- >= std::time::Duration::from_secs(CACHE_RATE)
- || (*ROUTES.lock().unwrap())
- .get(context.url.path())
- .is_some_and(|r| r.text_cache.is_empty())
- {
- (*LAST_CACHED.lock().unwrap()) = Instant::now();
-
- if let Some(route) = (*ROUTES.lock().unwrap()).get_mut(context.url.path()) {
- route.text_cache = response.to_string();
- info!("cache set for {}", context.url.path());
- } else {
- warn!(
- "cache could not be set for {} as it is not being tracked",
- context.url.path()
- );
- }
-
- trace!("recache for {}", {
- let path = context.url.path();
-
- if path.is_empty() {
- "/"
- } else {
- path
- }
- });
- }
-}