Concurrent cache
This commit is contained in:
parent
39ebfcb1db
commit
789ba410f7
5 changed files with 31 additions and 34 deletions
|
|
@ -1,7 +1,6 @@
|
|||
use crate::{cache, config::Config, repo::ReadRepoMetadataError, templates};
|
||||
|
||||
use askama::Template;
|
||||
use async_lock::Mutex;
|
||||
use log::error;
|
||||
use std::{
|
||||
io::{ErrorKind, Read},
|
||||
|
|
@ -15,14 +14,12 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
hl_registry.link_grammars();
|
||||
let hl_registry: &'static _ = Box::leak(Box::new(hl_registry));
|
||||
|
||||
let metadata_cache: &'static _ = Box::leak(Box::new(Mutex::new(cache::Cache::<
|
||||
let metadata_cache: &'static _ = Box::leak(Box::new(cache::Cache::<
|
||||
String,
|
||||
templates::Directory,
|
||||
>::default())));
|
||||
let file_cache: &'static _ = Box::leak(Box::new(Mutex::new(cache::Cache::<
|
||||
(String, String),
|
||||
String,
|
||||
>::default())));
|
||||
>::default()));
|
||||
let file_cache: &'static _ =
|
||||
Box::leak(Box::new(cache::Cache::<(String, String), String>::default()));
|
||||
let client: &'static _ = Box::leak(Box::new(async_lock::Mutex::new(
|
||||
crate::api_client::make_client(),
|
||||
)));
|
||||
|
|
@ -133,11 +130,8 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
}
|
||||
Some(root)
|
||||
};
|
||||
// TODO replace mutex with better thing (less contention or async mutex)
|
||||
let Some(root) = metadata_cache
|
||||
.lock()
|
||||
.await
|
||||
.fetch(repo_hash_str.to_string(), fetch_metadata)
|
||||
let Some(root) =
|
||||
metadata_cache.fetch(repo_hash_str.to_string(), fetch_metadata)
|
||||
else {
|
||||
return conn.with_status(404);
|
||||
};
|
||||
|
|
@ -169,7 +163,7 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
|
||||
Some(buf)
|
||||
};
|
||||
let Some(file_content) = file_cache.lock().await.fetch(
|
||||
let Some(file_content) = file_cache.fetch(
|
||||
(repo_hash_str.to_string(), file_hash.to_string()),
|
||||
fetch_file,
|
||||
) else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue