pub struct Cache { /* private fields */ }Expand description
Per-vendor cache directory and helper API.
Construct with Cache::for_vendor; the directory is created lazily.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn for_vendor(vendor: &str) -> Result<Self>
pub fn for_vendor(vendor: &str) -> Result<Self>
Build a cache rooted at ~/.cache/ai-usagebar/<vendor> (or under
$XDG_CACHE_HOME when set).
Sourcepub fn ensure_dir(&self) -> Result<()>
pub fn ensure_dir(&self) -> Result<()>
Ensure the directory exists. Safe to call repeatedly.
pub fn dir(&self) -> &Path
pub fn payload_path(&self) -> PathBuf
pub fn stale_path(&self) -> PathBuf
pub fn last_error_path(&self) -> PathBuf
pub fn lock_path(&self) -> PathBuf
Sourcepub fn payload_age(&self) -> Option<Duration>
pub fn payload_age(&self) -> Option<Duration>
Age of the payload (None if it doesn’t exist). Used by the widget to
decide whether the 60s cache window applies.
Sourcepub fn fresh_payload(&self, ttl: Duration) -> Result<Option<Vec<u8>>>
pub fn fresh_payload(&self, ttl: Duration) -> Result<Option<Vec<u8>>>
Returns the cached payload only if it is younger than ttl. Used as
the fast path in _fetch_usage (claudebar:343-349).
Sourcepub fn maybe_payload(&self) -> Result<Option<Vec<u8>>>
pub fn maybe_payload(&self) -> Result<Option<Vec<u8>>>
Read the payload regardless of age. Err if the file exists but is
unreadable; Ok(None) if it just doesn’t exist.
Sourcepub fn write_payload(&self, bytes: &[u8]) -> Result<()>
pub fn write_payload(&self, bytes: &[u8]) -> Result<()>
Atomically write a new payload. Uses tempfile + persist (POSIX
rename), matching claudebar’s mktemp + mv invariant.
Sourcepub fn mark_stale(&self)
pub fn mark_stale(&self)
Mark the cache as stale. Idempotent.
pub fn is_stale(&self) -> bool
Sourcepub fn write_last_error(&self, code: u16, msg: &str)
pub fn write_last_error(&self, code: u16, msg: &str)
Write the .last_error marker — first line code, second line msg.
Best-effort, never errors (matches claudebar:478-486 which silently
continues if the cache dir isn’t writable).
pub fn read_last_error(&self) -> Option<(u16, String)>
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 UnsafeUnpin 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