eure_env/cache/mod.rs
1//! Remote schema caching module.
2//!
3//! This module provides caching for remote schema files fetched over HTTP(S).
4//!
5//! # Module Organization
6//!
7//! - **Core types** (always available): `CacheMeta`, `CacheKeyInfo`, path computation
8//! - **Native I/O** (requires `native` feature): `fetch`, `FsStorage`, `gc`
9//!
10//! # Cache Layout
11//!
12//! The cache is stored in `~/.cache/eure/schemas/` (or `$EURE_CACHE_DIR`).
13//! Files are organized with 2-level directory sharding to prevent overcrowding:
14//!
15//! ```text
16//! ~/.cache/eure/schemas/
17//! eure.dev/
18//! a1/
19//! b2/
20//! a1b2c3d4-eure-schema.schema.eure # content
21//! a1b2c3d4-eure-schema.schema.eure.meta # metadata (JSON)
22//! ```
23//!
24//! # Example (native only)
25//!
26//! ```no_run
27//! use url::Url;
28//! use eure_env::cache::{fetch, CacheOptions};
29//!
30//! let url = Url::parse("https://eure.dev/v0.1.0/schemas/eure-schema.schema.eure").unwrap();
31//! let result = fetch(&url, &CacheOptions::default()).unwrap();
32//! println!("Content: {}", result.content);
33//! println!("From cache: {}", result.from_cache);
34//! ```
35
36// Core types (pure computation, always available)
37mod meta;
38mod path;
39
40pub use meta::{CacheAction, CacheMeta, ConditionalHeaders};
41pub use path::{
42 CacheKeyInfo, compute_cache_key, compute_content_hash, lock_path, meta_path, url_to_cache_path,
43};
44
45// Native I/O (requires filesystem and network)
46#[cfg(feature = "native")]
47mod error;
48#[cfg(feature = "native")]
49mod fetch;
50#[cfg(feature = "native")]
51mod gc;
52#[cfg(feature = "native")]
53mod storage;
54
55#[cfg(feature = "native")]
56pub use error::CacheError;
57#[cfg(feature = "native")]
58pub use fetch::{CacheOptions, FetchResult, default_cache_dir, fetch};
59#[cfg(feature = "native")]
60pub use gc::{clean, clean_with_dir, gc, gc_with_dir, parse_duration, parse_size};
61#[cfg(feature = "native")]
62pub use storage::{CacheEntry, CacheStorage, FsStorage, GcOptions, GcStats};