Cache refactor - add an in-memory cache, so redis is not needed
This commit is contained in:
parent
d1d2d4e44d
commit
996ff84c5b
10 changed files with 263 additions and 146 deletions
|
@ -5,7 +5,9 @@
|
|||
|
||||
use mimalloc::MiMalloc;
|
||||
use std::net::TcpListener;
|
||||
use websurfx::{config::parser::Config, run};
|
||||
use websurfx::{
|
||||
cache::cacher::Cache, cache::redis_cacher::RedisCache, config::parser::Config, run,
|
||||
};
|
||||
|
||||
/// A dhat heap memory profiler
|
||||
#[cfg(feature = "dhat-heap")]
|
||||
|
@ -30,6 +32,14 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
// Initialize the parsed config file.
|
||||
let config = Config::parse(false).unwrap();
|
||||
let cache = match &config.redis_url {
|
||||
Some(url) => Cache::new(
|
||||
RedisCache::new(url, 5)
|
||||
.await
|
||||
.expect("Redis cache configured"),
|
||||
),
|
||||
None => Cache::new_in_memory(),
|
||||
};
|
||||
|
||||
log::info!(
|
||||
"started server on port {} and IP {}",
|
||||
|
@ -44,5 +54,5 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
|
||||
|
||||
run(listener, config)?.await
|
||||
run(listener, config, cache)?.await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue