Fix git rebase problems, and the failing doctest

This commit is contained in:
Zsombor Gegesy 2023-09-14 20:26:08 +02:00
parent 1e7805cf42
commit e69126c5ea
6 changed files with 121 additions and 15 deletions

16
src/cache/cacher.rs vendored
View file

@ -8,7 +8,7 @@ use mini_moka::sync::Cache as MokaCache;
use std::time::Duration;
use tokio::sync::Mutex;
use crate::{config::parser::Config, results::aggregation_models::SearchResults};
use crate::{config::parser::Config, models::aggregation_models::SearchResults};
use super::error::PoolError;
#[cfg(feature = "redis-cache")]
@ -29,9 +29,9 @@ pub enum Cache {
impl Cache {
/// Builds the cache from the given configuration.
pub async fn build(config: &Config) -> Self {
pub async fn build(_config: &Config) -> Self {
#[cfg(feature = "redis-cache")]
if let Some(url) = &config.redis_url {
if let Some(url) = &_config.redis_url {
log::info!("Using Redis running at {} for caching", &url);
return Cache::new(
RedisCache::new(url, 5)
@ -40,12 +40,15 @@ impl Cache {
);
}
#[cfg(feature = "memory-cache")]
if config.in_memory_cache {
{
log::info!("Using an in-memory cache");
return Cache::new_in_memory();
}
log::info!("Caching is disabled");
Cache::Disabled
#[cfg(not(feature = "memory-cache"))]
{
log::info!("Caching is disabled");
Cache::Disabled
}
}
/// Creates a new cache, which wraps the given RedisCache.
@ -117,6 +120,7 @@ impl Cache {
/// A structure to efficiently share the cache between threads - as it is protected by a Mutex.
pub struct SharedCache {
/// The internal cache protected from concurrent access by a mutex
cache: Mutex<Cache>,
}

2
src/cache/error.rs vendored
View file

@ -16,7 +16,7 @@ pub enum PoolError {
PoolExhaustionWithConnectionDropError,
/// Whenever serialization or deserialization fails during communication with the cache.
SerializationError,
/// Returned when the value is missing.
/// Returned when the value is missing.
MissingValue,
}

View file

@ -20,8 +20,6 @@ pub struct Config {
/// It stores the redis connection url address on which the redis
/// client should connect.
pub redis_url: Option<String>,
/// enable/disable the in-memory cache. Only checked, when no redis_url is provided.
pub in_memory_cache: bool,
/// It stores the option to whether enable or disable production use.
pub aggregator: AggregatorConfig,
/// It stores the option to whether enable or disable logs.
@ -102,10 +100,6 @@ impl Config {
globals.get::<_, String>("colorscheme")?,
),
redis_url: globals.get::<_, String>("redis_url").ok(),
in_memory_cache: globals
.get::<_, bool>("in_memory_cache")
.ok()
.unwrap_or(false),
aggregator: AggregatorConfig {
random_delay: globals.get::<_, bool>("production_use")?,
},

View file

@ -40,7 +40,7 @@ use handler::paths::{file_path, FileType};
///
/// ```rust
/// use std::net::TcpListener;
/// use websurfx::{config::parser::Config, run};
/// use websurfx::{config::parser::Config, run, cache::cacher::Cache};
///
/// let config = Config::parse(true).unwrap();
/// let listener = TcpListener::bind("127.0.0.1:8080").expect("Failed to bind address");