pg_embedded_setup_unpriv/cache/mod.rs
1//! Shared binary cache for `PostgreSQL` downloads.
2//!
3//! This module provides caching infrastructure to avoid repeated downloads of
4//! `PostgreSQL` binaries when multiple tests or processes need the same version.
5//! Binaries are stored in a user-specific cache directory and shared across test
6//! runs.
7//!
8//! # Cache Location
9//!
10//! The cache directory is resolved by [`resolve_cache_dir`] in the following order:
11//!
12//! 1. `PG_BINARY_CACHE_DIR` environment variable if set
13//! 2. `$XDG_CACHE_HOME/pg-embedded/binaries` if `XDG_CACHE_HOME` is set
14//! 3. `~/.cache/pg-embedded/binaries` if the home directory is available
15//! 4. `/tmp/pg-embedded/binaries` as last resort when none of the above are available
16//!
17//! # Cross-Process Coordination
18//!
19//! The cache uses file-based locking to coordinate downloads across parallel
20//! test runners. Locks are per-version, allowing different versions to be
21//! downloaded concurrently.
22
23mod config;
24mod lock;
25mod operations;
26
27pub use config::{BinaryCacheConfig, resolve_cache_dir};
28pub use lock::CacheLock;
29pub use operations::{
30 CacheLookupResult, check_cache, copy_from_cache, find_matching_cached_version, populate_cache,
31 try_populate_cache, try_use_cache,
32};