pub struct SchemaCache { /* private fields */ }Expand description
Thread-safe LRU schema cache
Uses interior mutability with RwLock for thread-safe access.
Multiple threads can read concurrently, while writes are exclusive.
§Examples
use hedl_json::schema_cache::{SchemaCache, SchemaCacheKey};
let cache = SchemaCache::new(100);
// Cache a schema
let key = SchemaCacheKey::new(vec!["id".to_string(), "name".to_string()]);
cache.insert(key.clone(), vec!["id".to_string(), "name".to_string()]);
// Retrieve from cache
if let Some(schema) = cache.get(&key) {
println!("Schema: {:?}", schema);
}
// Get statistics
let stats = cache.statistics();
println!("Hit rate: {:.2}%", stats.hit_rate() * 100.0);Implementations§
Source§impl SchemaCache
impl SchemaCache
Sourcepub fn get(&self, key: &SchemaCacheKey) -> Option<Vec<String>>
pub fn get(&self, key: &SchemaCacheKey) -> Option<Vec<String>>
Get a schema from the cache
Returns Some(schema) if found, None otherwise.
Updates access statistics for LRU tracking.
§Arguments
key- Cache key representing the JSON structure
§Examples
use hedl_json::schema_cache::{SchemaCache, SchemaCacheKey};
let cache = SchemaCache::new(100);
let key = SchemaCacheKey::new(vec!["id".to_string()]);
if let Some(schema) = cache.get(&key) {
println!("Found: {:?}", schema);
}Sourcepub fn insert(&self, key: SchemaCacheKey, schema: Vec<String>)
pub fn insert(&self, key: SchemaCacheKey, schema: Vec<String>)
Insert a schema into the cache
If the cache is full, evicts the least recently used entry.
§Arguments
key- Cache key representing the JSON structureschema- Schema to cache (column names in order)
§Examples
use hedl_json::schema_cache::{SchemaCache, SchemaCacheKey};
let cache = SchemaCache::new(100);
let key = SchemaCacheKey::new(vec!["id".to_string(), "name".to_string()]);
cache.insert(key, vec!["id".to_string(), "name".to_string()]);Sourcepub fn statistics(&self) -> CacheStatistics
pub fn statistics(&self) -> CacheStatistics
Get current cache statistics
Returns a snapshot of cache performance metrics.
§Examples
use hedl_json::schema_cache::SchemaCache;
let cache = SchemaCache::new(100);
let stats = cache.statistics();
println!("Hit rate: {:.2}%", stats.hit_rate() * 100.0);
println!("Size: {}/{}", stats.size, stats.capacity);Sourcepub fn clear(&self)
pub fn clear(&self)
Clear the cache and reset statistics
§Examples
use hedl_json::schema_cache::SchemaCache;
let cache = SchemaCache::new(100);
cache.clear();Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get current cache size
§Examples
use hedl_json::schema_cache::SchemaCache;
let cache = SchemaCache::new(100);
assert_eq!(cache.len(), 0);Trait Implementations§
Source§impl Clone for SchemaCache
impl Clone for SchemaCache
Source§fn clone(&self) -> SchemaCache
fn clone(&self) -> SchemaCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SchemaCache
impl RefUnwindSafe for SchemaCache
impl Send for SchemaCache
impl Sync for SchemaCache
impl Unpin for SchemaCache
impl UnwindSafe for SchemaCache
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