Expand description
§lintel-schema-cache
Disk-backed cache for JSON Schema files. Fetches schemas over HTTP and stores them locally for fast subsequent lookups.
§Features
- Transparent caching — schemas are stored as
<cache_dir>/<hash>.jsonwhere<hash>is a deterministic hash of the URI - Pluggable HTTP — bring your own HTTP client via the
HttpClienttrait, or use the built-inUreqClient - jsonschema integration — implements both
jsonschema::Retrieveandjsonschema::AsyncRetrievefor seamless use as a schema resolver
§Usage
use lintel_schema_cache::{SchemaCache, ReqwestClient};
let cache = SchemaCache::new(None, ReqwestClient::default(), false, None);
// Use cache.fetch(uri) to retrieve schemas — returns (Value, CacheStatus)
// CacheStatus: Hit (from disk), Miss (fetched and cached), or Disabled (no cache dir)§Custom HTTP Client
use lintel_schema_cache::{SchemaCache, HttpClient};
#[derive(Clone)]
struct MyClient;
#[async_trait::async_trait]
impl HttpClient for MyClient {
async fn get(&self, uri: &str) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
// your HTTP implementation
todo!()
}
}
let cache = SchemaCache::new(None, MyClient, false, None);§License
Apache-2.0
Structs§
- Conditional
Response - Response from a conditional HTTP request.
- Reqwest
Client - Default HTTP client using reqwest.
- Schema
Cache - A disk-backed cache for JSON Schema files.
Enums§
- Cache
Status - Whether a schema was served from disk cache or fetched from the network.
Constants§
- DEFAULT_
SCHEMA_ CACHE_ TTL - Default TTL for cached schemas (12 hours).
Traits§
- Http
Client - Trait for fetching content over HTTP.
Functions§
- ensure_
cache_ dir - Return a usable cache directory for schemas, creating it if necessary.