pub struct SchemaCache<C: HttpClient = ReqwestClient> { /* private fields */ }Expand description
A disk-backed cache for JSON Schema files.
Schemas are fetched via HTTP and stored as <cache_dir>/<hash>.json
where <hash> is a hex-encoded hash 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<C: HttpClient> SchemaCache<C>
impl<C: HttpClient> SchemaCache<C>
pub fn new( cache_dir: Option<PathBuf>, client: C, skip_read: bool, ttl: Option<Duration>, ) -> Self
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<C: HttpClient> AsyncRetrieve for SchemaCache<C>
impl<C: HttpClient> AsyncRetrieve for SchemaCache<C>
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,
Asynchronously retrieve a resource from the given URI. Read more
Source§impl<C: Clone + HttpClient> Clone for SchemaCache<C>
impl<C: Clone + HttpClient> Clone for SchemaCache<C>
Source§fn clone(&self) -> SchemaCache<C>
fn clone(&self) -> SchemaCache<C>
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<C> Freeze for SchemaCache<C>where
C: Freeze,
impl<C> RefUnwindSafe for SchemaCache<C>where
C: RefUnwindSafe,
impl<C> Send for SchemaCache<C>
impl<C> Sync for SchemaCache<C>
impl<C> Unpin for SchemaCache<C>where
C: Unpin,
impl<C> UnsafeUnpin for SchemaCache<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for SchemaCache<C>where
C: UnwindSafe,
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