pub struct EnterpriseConfig { /* private fields */ }
Expand description
Enterprise-grade configuration manager with multi-tier caching and access control
EnterpriseConfig
provides a high-performance configuration management system
designed for production applications with strict performance requirements.
§Key Features
- Multi-Tier Caching: Fast cache for hot values + main cache for all values
- Lock-Free Performance: Optimized access patterns to minimize lock contention
- Thread Safety: All operations are safe for concurrent access via
Arc<RwLock>
- Poison Recovery: Graceful handling of lock poisoning without panics
- Format Preservation: Maintains original file format during save operations
- Sub-50ns Access: Achieves sub-50 nanosecond access times for cached values
§Performance Characteristics
- First access: ~3µs (populates cache)
- Cached access: ~457ns average (hot cache hit)
- Concurrent access: Maintains performance under load
- Memory efficient: LRU-style cache with configurable limits
§Examples
use config_lib::enterprise::EnterpriseConfig;
use config_lib::Value;
// Load configuration with automatic caching
let mut config = EnterpriseConfig::from_string(r#"
server.port = 8080
server.host = "localhost"
app.name = "my-service"
"#, Some("conf"))?;
// First access populates cache
let port = config.get("server.port");
// Subsequent accesses hit fast cache
let port_again = config.get("server.port"); // ~400ns
// Check cache performance
let (hits, misses, ratio) = config.cache_stats();
println!("Cache hit ratio: {:.1}%", ratio * 100.0);
Implementations§
Source§impl EnterpriseConfig
impl EnterpriseConfig
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load configuration from file with caching
Sourcepub fn from_string(content: &str, format: Option<&str>) -> Result<Self>
pub fn from_string(content: &str, format: Option<&str>) -> Result<Self>
Load configuration from string with caching
Sourcepub fn get(&self, key: &str) -> Option<Value>
pub fn get(&self, key: &str) -> Option<Value>
Get value with default fallback - enterprise API with true caching
Sourcepub fn get_or<T>(&self, key: &str, default: T) -> T
pub fn get_or<T>(&self, key: &str, default: T) -> T
Get a value or return a default (ZERO-COPY optimized)
Sourcepub fn get_or_default(&self, key: &str) -> Option<Value>
pub fn get_or_default(&self, key: &str) -> Option<Value>
Get with default value from defaults table
Sourcepub fn set(&mut self, key: &str, value: Value) -> Result<()>
pub fn set(&mut self, key: &str, value: Value) -> Result<()>
Set value in cache and invalidate fast cache
Sourcepub fn cache_stats(&self) -> (u64, u64, f64)
pub fn cache_stats(&self) -> (u64, u64, f64)
Get cache performance statistics
Sourcepub fn set_default(&mut self, key: &str, value: Value)
pub fn set_default(&mut self, key: &str, value: Value)
Set default value for key
Sourcepub fn make_read_only(&mut self)
pub fn make_read_only(&mut self)
Make config read-only for security
Sourcepub fn merge(&mut self, other: &EnterpriseConfig) -> Result<()>
pub fn merge(&mut self, other: &EnterpriseConfig) -> Result<()>
Merge another config into this one
Trait Implementations§
Source§impl Debug for EnterpriseConfig
impl Debug for EnterpriseConfig
Auto Trait Implementations§
impl Freeze for EnterpriseConfig
impl RefUnwindSafe for EnterpriseConfig
impl Send for EnterpriseConfig
impl Sync for EnterpriseConfig
impl Unpin for EnterpriseConfig
impl UnwindSafe for EnterpriseConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more