feat: separated feature cache
This commit is contained in:
parent
8ecc83fe78
commit
32b173966c
11 changed files with 76 additions and 36 deletions
|
|
@ -12,9 +12,10 @@ publish = false
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["http3-quinn"]
|
||||
default = ["http3-quinn", "cache"]
|
||||
http3-quinn = ["rpxy-lib/http3-quinn"]
|
||||
http3-s2n = ["rpxy-lib/http3-s2n"]
|
||||
cache = ["rpxy-lib/cache"]
|
||||
|
||||
[dependencies]
|
||||
rpxy-lib = { path = "../rpxy-lib/", default-features = false, features = [
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
use rpxy_lib::{reexports::Uri, AppConfig, ProxyConfig, ReverseProxyConfig, TlsConfig, UpstreamUri};
|
||||
use rustc_hash::FxHashMap as HashMap;
|
||||
use serde::Deserialize;
|
||||
use std::{fs, net::SocketAddr, path::PathBuf};
|
||||
use std::{fs, net::SocketAddr};
|
||||
|
||||
#[derive(Deserialize, Debug, Default, PartialEq, Eq, Clone)]
|
||||
pub struct ConfigToml {
|
||||
|
|
@ -32,6 +32,7 @@ pub struct Http3Option {
|
|||
pub max_idle_timeout: Option<u64>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cache")]
|
||||
#[derive(Deserialize, Debug, Default, PartialEq, Eq, Clone)]
|
||||
pub struct CacheOption {
|
||||
pub cache_dir: Option<String>,
|
||||
|
|
@ -43,6 +44,7 @@ pub struct CacheOption {
|
|||
pub struct Experimental {
|
||||
#[cfg(any(feature = "http3-quinn", feature = "http3-s2n"))]
|
||||
pub h3: Option<Http3Option>,
|
||||
#[cfg(feature = "cache")]
|
||||
pub cache: Option<CacheOption>,
|
||||
pub ignore_sni_consistency: Option<bool>,
|
||||
}
|
||||
|
|
@ -169,20 +171,19 @@ impl TryInto<ProxyConfig> for &ConfigToml {
|
|||
proxy_config.sni_consistency = !ignore;
|
||||
}
|
||||
|
||||
#[cfg(feature = "cache")]
|
||||
if let Some(cache_option) = &exp.cache {
|
||||
proxy_config.cache_enabled = true;
|
||||
proxy_config.cache_dir = match &cache_option.cache_dir {
|
||||
Some(cache_dir) => Some(PathBuf::from(cache_dir)),
|
||||
None => Some(PathBuf::from(CACHE_DIR)),
|
||||
};
|
||||
proxy_config.cache_max_entry = match &cache_option.max_cache_entry {
|
||||
Some(num) => Some(*num),
|
||||
None => Some(MAX_CACHE_ENTRY),
|
||||
};
|
||||
proxy_config.cache_max_each_size = match &cache_option.max_cache_each_size {
|
||||
Some(num) => Some(*num),
|
||||
None => Some(MAX_CACHE_EACH_SIZE),
|
||||
Some(cache_dir) => Some(std::path::PathBuf::from(cache_dir)),
|
||||
None => Some(std::path::PathBuf::from(CACHE_DIR)),
|
||||
};
|
||||
if let Some(num) = cache_option.max_cache_entry {
|
||||
proxy_config.cache_max_entry = num;
|
||||
}
|
||||
if let Some(num) = cache_option.max_cache_each_size {
|
||||
proxy_config.cache_max_each_size = num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,6 @@ pub const LISTEN_ADDRESSES_V4: &[&str] = &["0.0.0.0"];
|
|||
pub const LISTEN_ADDRESSES_V6: &[&str] = &["[::]"];
|
||||
pub const CONFIG_WATCH_DELAY_SECS: u32 = 20;
|
||||
|
||||
#[cfg(feature = "cache")]
|
||||
// Cache directory
|
||||
pub const CACHE_DIR: &str = "./cache";
|
||||
// # of entries in cache
|
||||
pub const MAX_CACHE_ENTRY: usize = 1_000;
|
||||
// max size for each file in bytes
|
||||
pub const MAX_CACHE_EACH_SIZE: usize = 65_535;
|
||||
|
||||
// TODO: max cache size in total
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue