Skip to main content

eure_env/cache/
mod.rs

1//! Caching module for eure.
2//!
3//! This module provides caching infrastructure with support for multiple cache types.
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 the platform-specific cache directory (via `directories` crate):
13//! - macOS: `~/Library/Caches/dev.eure.eure/`
14//! - Linux: `~/.cache/eure/`
15//! - Windows: `C:\Users\<User>\AppData\Local\eure\eure\cache\`
16//!
17//! Override with `$EURE_CACHE_DIR` environment variable.
18//!
19//! Cache types are stored in subdirectories:
20//!
21//! ```text
22//! ~/Library/Caches/dev.eure.eure/  # base_cache_dir() (macOS example)
23//!   https/                          # https_cache_dir() - HTTPS fetched content
24//!     eure.dev/
25//!       a1/
26//!         b2/
27//!           a1b2c3d4-schema.eure       # content
28//!           a1b2c3d4-schema.eure.meta  # metadata (JSON)
29//!   # (future: compile/, build/, etc.)
30//! ```
31//!
32//! # Example (native only)
33//!
34//! ```no_run
35//! use url::Url;
36//! use eure_env::cache::{fetch, CacheOptions};
37//!
38//! let url = Url::parse("https://eure.dev/v0.1.0/schemas/eure-schema.schema.eure").unwrap();
39//! let result = fetch(&url, &CacheOptions::default()).unwrap();
40//! println!("Content: {}", result.content);
41//! println!("From cache: {}", result.from_cache);
42//! ```
43
44// Core types (pure computation, always available)
45mod meta;
46mod path;
47
48pub use meta::{CacheAction, CacheMeta, ConditionalHeaders};
49pub use path::{
50    CacheKeyInfo, compute_cache_key, compute_content_hash, lock_path, meta_path, url_to_cache_path,
51};
52
53// Native I/O (requires filesystem and network)
54#[cfg(feature = "native")]
55mod error;
56#[cfg(feature = "native")]
57mod fetch;
58#[cfg(feature = "native")]
59mod gc;
60#[cfg(feature = "native")]
61mod storage;
62
63#[cfg(feature = "native")]
64pub use error::CacheError;
65#[cfg(feature = "native")]
66pub use fetch::{CacheOptions, FetchResult, base_cache_dir, fetch, https_cache_dir};
67#[cfg(feature = "native")]
68pub use gc::{clean, clean_with_dir, gc, gc_with_dir, parse_duration, parse_size};
69#[cfg(feature = "native")]
70pub use storage::{CacheEntry, CacheStorage, FsStorage, GcOptions, GcStats};