pub struct WorkspaceCache { /* private fields */ }Expand description
Handle to the cache directory for a single workspace. Construction is
cheap (creates directories on demand); the same handle can be shared
across threads via Arc — it holds no mutable state.
Implementations§
Source§impl WorkspaceCache
impl WorkspaceCache
Sourcepub fn new(root: &Path) -> Option<Self>
pub fn new(root: &Path) -> Option<Self>
Create (or re-open) the cache directory for a workspace rooted at
root. Returns None when the system has no usable home/cache
directory — callers should treat that as “cache disabled” and
proceed without persistence.
If the existing cache directory exceeds CACHE_SIZE_CAP, it is
cleared before the handle is returned. That’s a coarse knob —
K3 could refine to LRU-by-mtime — but crossing 512 MiB at
startup indicates the workspace itself has more files than the
cap fits, and the rebuild cost is bounded to one full
re-scan.
Sourcepub fn size_bytes(&self) -> Result<u64>
pub fn size_bytes(&self) -> Result<u64>
Total bytes consumed by this workspace’s cache directory, including
nested subdirectories — mir’s AnalysisCache lives under a session/
subdirectory of this one (see set_session_cache_dir), so the layout
isn’t flat even though this directory’s own entries are.
Sourcepub fn with_dir(dir: PathBuf) -> Self
pub fn with_dir(dir: PathBuf) -> Self
Override the root directory directly. The directory is used verbatim
(no schema / workspace subdirectories are appended). Use for tests or
when the caller provides an explicit cachePath initializationOption.
Sourcepub fn key_for(uri: &str, content: &str) -> CacheKey
pub fn key_for(uri: &str, content: &str) -> CacheKey
Build a cache key for (uri, content). The filename half (uri_hash)
stays fixed across edits to the same URI so a re-index overwrites its
existing slot; the validation half (content_hash) changes on every
edit so a read against stale content misses.
Sourcepub fn read<T: DeserializeOwned>(&self, key: &CacheKey) -> Option<T>
pub fn read<T: DeserializeOwned>(&self, key: &CacheKey) -> Option<T>
Deserialize a previously-cached value. Returns None on any I/O
or decode failure, or when the entry’s stored content hash no
longer matches key (the slot holds a stale revision) — all of
which should look identical to a missing entry so callers fall
through to the recompute path.
Sourcepub fn write<T: Serialize>(&self, key: &CacheKey, value: &T) -> Result<()>
pub fn write<T: Serialize>(&self, key: &CacheKey, value: &T) -> Result<()>
Atomically publish an entry to the cache. Writes to a sibling temp file then renames, so readers never see a half-written payload even if the process dies mid-write. Because the filename is keyed on URI alone, this overwrites whatever revision (if any) previously occupied the slot rather than leaving it behind.
No fsync: the cache is advisory-only — a crash that loses a write just produces a cache miss on the next startup, which safely falls back to re-parsing. Skipping sync_all() avoids 5–15 ms per file on macOS, which on a 1,500-file project accounts for most of the cold indexing time.
Trait Implementations§
Source§impl Clone for WorkspaceCache
impl Clone for WorkspaceCache
Source§fn clone(&self) -> WorkspaceCache
fn clone(&self) -> WorkspaceCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for WorkspaceCache
impl RefUnwindSafe for WorkspaceCache
impl Send for WorkspaceCache
impl Sync for WorkspaceCache
impl Unpin for WorkspaceCache
impl UnsafeUnpin for WorkspaceCache
impl UnwindSafe for WorkspaceCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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