pub struct LockFileCache { /* private fields */ }Expand description
Cache for parsed lock files with automatic staleness detection.
Caches parsed lock file contents and checks file modification time to avoid re-parsing unchanged files. Thread-safe for concurrent access.
Bounded by a capacity (DEFAULT_MAX_CACHED_LOCKFILES by default, via Self::new; a
custom bound via Self::with_capacity): once full, inserting a new key evicts the
least-recently-used entry first, keyed by CachedLockFile::parsed_at, which is
refreshed on every cache hit as well as every (re)parse (#962).
§Examples
use deps_core::lockfile::LockFileCache;
use std::path::Path;
let cache = LockFileCache::new();
// First call parses the file
// Second call returns cached result if file hasn't changedImplementations§
Source§impl LockFileCache
impl LockFileCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty lock file cache, capped at DEFAULT_MAX_CACHED_LOCKFILES
entries.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new empty lock file cache, capped at capacity entries.
§Examples
use deps_core::lockfile::LockFileCache;
let cache = LockFileCache::with_capacity(64);
assert!(cache.is_empty());Sourcepub async fn get_or_parse(
&self,
provider: &dyn LockFileProvider,
lockfile_path: &Path,
) -> Result<ResolvedPackages>
pub async fn get_or_parse( &self, provider: &dyn LockFileProvider, lockfile_path: &Path, ) -> Result<ResolvedPackages>
Gets parsed packages from cache or parses the lock file.
Checks file modification time to detect changes. If the file has been modified since last parse, re-parses it. Otherwise, returns the cached result.
§Arguments
provider- Lock file provider implementationlockfile_path- Path to the lock file
§Returns
Resolved packages on success
§Errors
Returns error if file cannot be read or parsed
Sourcepub fn invalidate(&self, lockfile_path: &Path)
pub fn invalidate(&self, lockfile_path: &Path)
Invalidates cached entry for a lock file.
Forces next access to re-parse the file. Use when you know the file has changed but modification time might not reflect it.