Skip to main content

SchemaCache

Struct SchemaCache 

Source
pub struct SchemaCache { /* private fields */ }
Expand description

Thread-safe LRU cache for schema validators.

Caches parsed schemas to avoid re-parsing on every validation. Uses parking_lot RwLock for high-performance concurrent access.

§Example

use hedl_xml::schema::SchemaCache;
use std::path::Path;

let cache = SchemaCache::new(100);

// First call parses and caches
let validator = cache.get_or_load(Path::new("schema.xsd"))?;

// Second call uses cached validator
let validator2 = cache.get_or_load(Path::new("schema.xsd"))?;

Implementations§

Source§

impl SchemaCache

Source

pub fn new(max_size: usize) -> Self

Create a new schema cache with maximum size.

§Arguments
  • max_size - Maximum number of schemas to cache
§Example
use hedl_xml::schema::SchemaCache;

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

pub fn get_or_load( &self, path: &Path, ) -> Result<Arc<SchemaValidator>, ValidationError>

Get cached validator or load from file.

If the schema is already cached, returns the cached validator. Otherwise, loads the schema from file and caches it.

§Arguments
  • path - Path to schema file
§Errors

Returns ValidationError if schema file cannot be loaded or parsed.

§Example
use hedl_xml::schema::SchemaCache;
use std::path::Path;

let cache = SchemaCache::new(10);
let validator = cache.get_or_load(Path::new("schema.xsd"))?;
Source

pub fn clear(&self)

Clear all cached schemas.

§Example
use hedl_xml::schema::SchemaCache;

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

pub fn size(&self) -> usize

Get number of cached schemas.

§Example
use hedl_xml::schema::SchemaCache;

let cache = SchemaCache::new(10);
assert_eq!(cache.size(), 0);

Trait Implementations§

Source§

impl Default for SchemaCache

Source§

fn default() -> Self

Create default cache with size 100

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.