You've already forked AstralRinth
forked from didirus/AstralRinth
Project Types, Code Cleanup, and Rename Mods -> Projects (#192)
* Initial work for modpacks and project types * Code cleanup, fix some issues * Username route getting, remove pointless tests * Base validator types + fixes * Fix strange IML generation * Multiple hash requests for version files * Fix docker build (hopefully) * Legacy routes * Finish validator architecture * Update rust version in dockerfile * Added caching and fixed typo (#203) * Added caching and fixed typo * Fixed clippy error * Removed log for cache * Add final validators, fix how loaders are handled and add icons to tags * Fix search module * Fix parts of legacy API not working Co-authored-by: Redblueflame <contact@redblueflame.com>
This commit is contained in:
44
src/database/cache/mod.rs
vendored
Normal file
44
src/database/cache/mod.rs
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
//pub mod project_cache;
|
||||
//pub mod project_query_cache;
|
||||
#[macro_export]
|
||||
macro_rules! generate_cache {
|
||||
($name:ident,$id:ty, $val:ty, $cache_name:ident, $mod_name:ident, $getter_name:ident, $setter_name:ident) => {
|
||||
pub mod $mod_name {
|
||||
use cached::async_mutex::Mutex;
|
||||
use cached::{Cached, SizedCache};
|
||||
use lazy_static::lazy_static;
|
||||
lazy_static! {
|
||||
static ref $cache_name: Mutex<SizedCache<$id, $val>> =
|
||||
Mutex::new(SizedCache::with_size(400));
|
||||
}
|
||||
|
||||
pub async fn $getter_name<'a>(id: $id) -> Option<$val> {
|
||||
let mut cache = $cache_name.lock().await;
|
||||
Cached::cache_get(&mut *cache, &id).map(|e| e.clone())
|
||||
}
|
||||
pub async fn $setter_name<'a>(id: $id, val: &$val) {
|
||||
let mut cache = $cache_name.lock().await;
|
||||
Cached::cache_set(&mut *cache, id, val.clone());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
generate_cache!(
|
||||
project,
|
||||
String,
|
||||
crate::database::Project,
|
||||
PROJECT_CACHE,
|
||||
project_cache,
|
||||
get_cache_project,
|
||||
set_cache_project
|
||||
);
|
||||
generate_cache!(
|
||||
query_project,
|
||||
String,
|
||||
crate::database::models::project_item::QueryProject,
|
||||
QUERY_PROJECT_CACHE,
|
||||
query_project_cache,
|
||||
get_cache_query_project,
|
||||
set_cache_query_project
|
||||
);
|
||||
Reference in New Issue
Block a user