fix(cache): wire trusted-proxy cache and remove stale cache traces (#2581)

This commit is contained in:
houseme
2026-04-18 00:57:21 +08:00
committed by GitHub
parent 38eb0781cf
commit ffcf18f5f3
13 changed files with 231 additions and 51 deletions
+15 -5
View File
@@ -17,10 +17,10 @@
use std::sync::Arc;
use tower::Layer;
use crate::ProxyMetrics;
use crate::ProxyValidator;
use crate::TrustedProxyConfig;
use crate::TrustedProxyMiddleware;
use crate::{CacheConfig, ProxyMetrics};
/// Tower Layer for the trusted proxy middleware.
#[derive(Clone, Debug)]
@@ -34,12 +34,22 @@ pub struct TrustedProxyLayer {
impl TrustedProxyLayer {
/// Creates a new `TrustedProxyLayer`.
pub fn new(config: TrustedProxyConfig, metrics: Option<ProxyMetrics>, enabled: bool) -> Self {
let validator = ProxyValidator::new(config, metrics);
Self::with_cache_config(config, CacheConfig::default(), metrics, enabled)
}
Self {
validator: Arc::new(validator),
enabled,
/// Creates a new `TrustedProxyLayer` with explicit cache configuration.
pub fn with_cache_config(
config: TrustedProxyConfig,
cache_config: CacheConfig,
metrics: Option<ProxyMetrics>,
enabled: bool,
) -> Self {
let validator = Arc::new(ProxyValidator::with_cache_config(config, cache_config.clone(), metrics));
if enabled {
validator.spawn_cache_maintenance_task(cache_config.cleanup_interval());
}
Self { validator, enabled }
}
/// Creates a new `TrustedProxyLayer` that is enabled by default.