lintel-schema-cache
Disk-backed schema cache with HTTP fetching and JSON parsing. Part of the Lintel project. Fetches JSON schemas over HTTP and stores results locally for fast subsequent lookups.
Features
- SHA-256 keyed caching — schemas are stored as
<cache_dir>/<sha256>.jsonwhere<sha256>is the hex digest of the URI, avoiding hash collisions - Conditional requests — uses
ETag/If-None-Matchheaders to avoid re-downloading unchanged schemas - TTL support — configurable time-to-live for cache entries based on file modification time
- In-memory layer — frequently accessed schemas are also kept in memory for zero-IO lookups
- jsonschema integration — implements
jsonschema::AsyncRetrievefor seamless use as a schema resolver - Test-friendly —
SchemaCache::memory()constructor creates a memory-only cache with no HTTP or disk I/O
Usage
use SchemaCache;
use Duration;
// Uses sensible defaults: system cache dir, 12h TTL
let cache = builder.build;
// Or customize:
let cache = builder
.force_fetch
.ttl
.build;
let = cache.fetch.await?;
// status: Hit (from disk/memory), Miss (fetched and cached), or Disabled (no cache dir)
Testing
Use the memory-only constructor to avoid network and disk I/O in tests:
use SchemaCache;
let cache = memory;
cache.insert;
let = cache.fetch.await?;
License
Apache-2.0