pub struct ReleaseCache { /* private fields */ }Expand description
On-disk cache for GitHub release metadata.
Implementations§
Source§impl ReleaseCache
impl ReleaseCache
Sourcepub fn new(cache_dir: PathBuf, ttl: Duration) -> Self
pub fn new(cache_dir: PathBuf, ttl: Duration) -> Self
Create a new release cache backed by the given directory.
Sourcepub fn read_if_valid(&self, repo: &str) -> Option<Vec<GitHubRelease>>
pub fn read_if_valid(&self, repo: &str) -> Option<Vec<GitHubRelease>>
Return the cached releases if the cache file exists, belongs to the
same repo, and has not expired. Returns None on any error (missing,
corrupted, expired, wrong repo) — callers should fall back to the
network in that case.
Sourcepub fn lock_and_recheck(
&self,
repo: &str,
) -> Result<(ReleaseCacheLockGuard, Option<Vec<GitHubRelease>>)>
pub fn lock_and_recheck( &self, repo: &str, ) -> Result<(ReleaseCacheLockGuard, Option<Vec<GitHubRelease>>)>
Acquire the exclusive cache lock, re-check the cache, and return valid cached releases if another node populated them while we waited.
Returns Ok(Some(releases)) if a valid cache was found under the
lock, or Ok(None) if the cache is still stale/missing and the
caller should fetch from the network. The returned
The returned lock guard must be held until after writing the fresh
data so that other nodes block rather than all hitting the API.
Note: lock_exclusive() blocks the calling thread. Callers in
async contexts should wrap this in tokio::task::spawn_blocking.
§Errors
Returns an error if the lock file cannot be created or acquired.
Sourcepub fn write(&self, repo: &str, releases: &[GitHubRelease]) -> Result<()>
pub fn write(&self, repo: &str, releases: &[GitHubRelease]) -> Result<()>
Write releases to the cache, using an exclusive file lock to coordinate with other nodes on the same machine.
The write is atomic: data goes to a temp file first, then is renamed over the cache file.
§Errors
Returns an error if the lock cannot be acquired or the file cannot be written.
Sourcepub fn write_under_lock(
&self,
_guard: ReleaseCacheLockGuard,
repo: &str,
releases: &[GitHubRelease],
) -> Result<()>
pub fn write_under_lock( &self, _guard: ReleaseCacheLockGuard, repo: &str, releases: &[GitHubRelease], ) -> Result<()>
Write releases to the cache while the caller already holds the lock guard. The guard is consumed to ensure the lock is released after writing.
§Errors
Returns an error if the file cannot be written.
Trait Implementations§
Source§impl Clone for ReleaseCache
impl Clone for ReleaseCache
Source§fn clone(&self) -> ReleaseCache
fn clone(&self) -> ReleaseCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ReleaseCache
impl RefUnwindSafe for ReleaseCache
impl Send for ReleaseCache
impl Sync for ReleaseCache
impl Unpin for ReleaseCache
impl UnsafeUnpin for ReleaseCache
impl UnwindSafe for ReleaseCache
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