13 releases
Uses new Rust 2024
| new 0.0.13 | Mar 6, 2026 |
|---|---|
| 0.0.12 | Feb 27, 2026 |
#117 in Caching
176 downloads per month
Used in 12 crates
(6 directly)
26KB
379 lines
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 lintel_schema_cache::SchemaCache;
use std::time::Duration;
// Uses sensible defaults: system cache dir, 12h TTL
let cache = SchemaCache::builder().build();
// Or customize:
let cache = SchemaCache::builder()
.force_fetch(true)
.ttl(Duration::from_secs(3600))
.build();
let (schema, status) = cache.fetch("https://json.schemastore.org/tsconfig.json").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 lintel_schema_cache::SchemaCache;
let cache = SchemaCache::memory();
cache.insert("https://example.com/schema.json", serde_json::json!({"type": "object"}));
let (val, _status) = cache.fetch("https://example.com/schema.json").await?;
License
Apache-2.0
Dependencies
~19–39MB
~501K SLoC