Skip to main content

SchemaCache

Struct SchemaCache 

Source
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

Source

pub fn new(capacity: usize) -> Self

Create a new schema cache with the specified capacity

§Arguments
  • capacity - Maximum number of schemas to cache (default: 100)
§Examples
use hedl_json::schema_cache::SchemaCache;

let cache = SchemaCache::new(100);
Source

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);
}
Source

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 structure
  • schema - 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()]);
Source

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);
Source

pub fn clear(&self)

Clear the cache and reset statistics

§Examples
use hedl_json::schema_cache::SchemaCache;

let cache = SchemaCache::new(100);
cache.clear();
Source

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);
Source

pub fn is_empty(&self) -> bool

Check if cache is empty

§Examples
use hedl_json::schema_cache::SchemaCache;

let cache = SchemaCache::new(100);
assert!(cache.is_empty());
Source

pub fn capacity(&self) -> usize

Get cache capacity

§Examples
use hedl_json::schema_cache::SchemaCache;

let cache = SchemaCache::new(100);
assert_eq!(cache.capacity(), 100);

Trait Implementations§

Source§

impl Clone for SchemaCache

Source§

fn clone(&self) -> SchemaCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SchemaCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more