pub struct SchemaCache { /* private fields */ }Expand description
A disk-backed schema cache with HTTP fetching and JSON parsing.
Schemas are fetched via HTTP and stored as <cache_dir>/<hash>.json
where <hash> is a SHA-256 hex digest of the URI. When a schema is
requested, the cache is checked first; on a miss the schema is fetched
and written to disk for future use.
Implementations§
Source§impl SchemaCache
impl SchemaCache
Sourcepub fn builder() -> SchemaCacheBuilder
pub fn builder() -> SchemaCacheBuilder
Returns a builder pre-configured with sensible defaults.
cache_dir=ensure_cache_dir()ttl=DEFAULT_SCHEMA_CACHE_TTLforce_fetch=false
Sourcepub fn insert(&self, uri: &str, value: Value)
pub fn insert(&self, uri: &str, value: Value)
Insert a value into the in-memory cache (useful for tests).
Sourcepub fn content_hash(&self, uri: &str) -> Option<String>
pub fn content_hash(&self, uri: &str) -> Option<String>
Return the SHA-256 hex digest of the raw content last fetched for uri.
Returns None if the URI has not been fetched or was inserted via
insert (which has no raw content to hash).
Sourcepub fn hash_content(content: &str) -> String
pub fn hash_content(content: &str) -> String
Compute the SHA-256 hash of arbitrary content, returned as a 64-char hex string.
Sourcepub async fn fetch(
&self,
uri: &str,
) -> Result<(Value, CacheStatus), Box<dyn Error + Send + Sync>>
pub async fn fetch( &self, uri: &str, ) -> Result<(Value, CacheStatus), Box<dyn Error + Send + Sync>>
Fetch a schema by URI, using the disk cache when available.
Returns the parsed schema and a CacheStatus indicating whether the
result came from the disk cache, the network, or caching was disabled.
When skip_read is set, the cache read is skipped but fetched schemas
are still written to disk.
§Errors
Returns an error if the schema cannot be fetched from the network, read from disk cache, or parsed as JSON.
Trait Implementations§
Source§impl AsyncRetrieve for SchemaCache
impl AsyncRetrieve for SchemaCache
Source§fn retrieve<'life0, 'life1, 'async_trait>(
&'life0 self,
uri: &'life1 Uri<String>,
) -> Pin<Box<dyn Future<Output = Result<Value, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn retrieve<'life0, 'life1, 'async_trait>(
&'life0 self,
uri: &'life1 Uri<String>,
) -> Pin<Box<dyn Future<Output = Result<Value, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl Clone for SchemaCache
impl Clone for SchemaCache
Source§fn clone(&self) -> SchemaCache
fn clone(&self) -> SchemaCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more