pub struct Cache { /* private fields */ }Expand description
Git repository cache for efficient resource management.
Manages repository cloning, updating, version management, and resource copying.
Multiple instances can safely operate on same cache via CacheLock.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates cache instance with default platform-specific directory.
Linux/macOS: ~/.agpm/cache/, Windows: %LOCALAPPDATA%\agpm\cache\.
Override with AGPM_CACHE_DIR environment variable.
Sourcepub fn with_dir(dir: PathBuf) -> Result<Self>
pub fn with_dir(dir: PathBuf) -> Result<Self>
Creates cache instance with custom directory (useful for testing).
Sourcepub async fn ensure_cache_dir(&self) -> Result<()>
pub async fn ensure_cache_dir(&self) -> Result<()>
Ensures cache directory exists, creating if necessary. Safe to call multiple times.
Sourcepub fn get_worktree_path(&self, url: &str, sha: &str) -> Result<PathBuf>
pub fn get_worktree_path(&self, url: &str, sha: &str) -> Result<PathBuf>
Constructs worktree path for URL and SHA (does not check existence or create).
Sourcepub async fn get_or_clone_source(
&self,
name: &str,
url: &str,
version: Option<&str>,
) -> Result<PathBuf>
pub async fn get_or_clone_source( &self, name: &str, url: &str, version: Option<&str>, ) -> Result<PathBuf>
Gets or clones source repository to cache.
Handles cloning new repos and updating existing ones with file-based locking.
Concurrent calls with same name block; different names run in parallel.
§Arguments
name- Source identifier for cache directory and lockingurl- Git repository URL (HTTPS, SSH, or local)version- Optional Git ref (tag, branch, commit, or None for default)
Sourcepub async fn cleanup_worktree(&self, worktree_path: &Path) -> Result<()>
pub async fn cleanup_worktree(&self, worktree_path: &Path) -> Result<()>
Removes worktree using git worktree remove to properly clean up metadata.
This ensures both the worktree directory AND the bare repo’s metadata are cleaned up, preventing “missing but already registered worktree” errors on subsequent creation.
Sourcepub async fn cleanup_all_worktrees(&self) -> Result<()>
pub async fn cleanup_all_worktrees(&self) -> Result<()>
Removes all worktrees from cache and prunes bare repo references.
Sourcepub async fn get_or_create_worktree_for_sha(
&self,
name: &str,
url: &str,
sha: &str,
context: Option<&str>,
) -> Result<PathBuf>
pub async fn get_or_create_worktree_for_sha( &self, name: &str, url: &str, sha: &str, context: Option<&str>, ) -> Result<PathBuf>
Gets or creates SHA-based worktree with notification coordination.
First thread creates worktree, others wait on notification. SHA-based ensures maximum reuse and deterministic installations.
§Arguments
sha- Full 40-character commit SHA (pre-resolved)
Sourcepub async fn copy_resource(
&self,
source_dir: &Path,
source_path: &str,
target_path: &Path,
) -> Result<()>
pub async fn copy_resource( &self, source_dir: &Path, source_path: &str, target_path: &Path, ) -> Result<()>
Copies resource file from cached repository to project (silent).
Uses copy-based approach (not symlinks) for cross-platform compatibility and Git integration. Creates parent directories automatically.
§Arguments
source_dir- Cached repository pathsource_path- Relative path within repositorytarget_path- Absolute installation path
Sourcepub async fn copy_resource_with_output(
&self,
source_dir: &Path,
source_path: &str,
target_path: &Path,
show_output: bool,
) -> Result<()>
pub async fn copy_resource_with_output( &self, source_dir: &Path, source_path: &str, target_path: &Path, show_output: bool, ) -> Result<()>
Copies resource file with optional installation output.
Same as copy_resource but optionally displays “✅ Installed” messages.
§Arguments
show_output- Whether to display installation progress
Sourcepub async fn clean_unused(&self, active_sources: &[String]) -> Result<usize>
pub async fn clean_unused(&self, active_sources: &[String]) -> Result<usize>
Removes cached repositories not in active sources list.
Returns count of removed directories. Displays progress messages.
§Arguments
active_sources- Source names to preserve
Sourcepub async fn get_cache_size(&self) -> Result<u64>
pub async fn get_cache_size(&self) -> Result<u64>
Calculates total cache size in bytes (recursive, returns 0 if not exists).
Sourcepub fn get_cache_location(&self) -> &Path
pub fn get_cache_location(&self) -> &Path
Returns cache directory path (may not exist, use ensure_cache_dir to create).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cache
impl !RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl !UnwindSafe for Cache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more