pub struct FileParseCache { /* private fields */ }Expand description
Thread-safe LRU cache for parsed session analyses with automatic eviction.
Entries are held as Arc<CodeAnalysis> (the typed struct). We deliberately
avoid caching Arc<serde_json::Value> because serde_json::to_value deep-
clones every string and adds per-node Value enum overhead on top — for
long Claude sessions that roughly doubles the working set. Callers that
need a Value (CLI single-file dump) serialise on demand from the typed
form, which only happens once per request rather than once per cache entry.
Implementations§
Source§impl FileParseCache
impl FileParseCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new LRU cache with capacity from constants::capacity::FILE_CACHE_SIZE.
Sourcepub fn get_or_parse<P: AsRef<Path>>(&self, path: P) -> Result<Arc<CodeAnalysis>>
pub fn get_or_parse<P: AsRef<Path>>(&self, path: P) -> Result<Arc<CodeAnalysis>>
Retrieves cached analysis or parses the file if needed, auto-detecting the provider from file contents.
Prefer Self::get_or_parse_as whenever the caller already knows which
provider the file belongs to (e.g. walking a specific session
directory). Content detection is only safe for ad-hoc single-file paths.
Workflow:
- Check cache hit with read-only peek (no lock contention)
- If valid, promote entry to front with write lock
- If miss/stale, parse file and cache result (may evict LRU entry)
Optimized to minimize write lock contention in parallel workloads.
§Errors
Returns an error if the file’s metadata cannot be read or if parsing the session file fails (malformed data, unreadable contents, etc.). A poisoned cache lock does not error — it simply forces a reparse.
Sourcepub fn get_or_parse_as<P: AsRef<Path>>(
&self,
path: P,
provider: ExtensionType,
) -> Result<Arc<CodeAnalysis>>
pub fn get_or_parse_as<P: AsRef<Path>>( &self, path: P, provider: ExtensionType, ) -> Result<Arc<CodeAnalysis>>
Same as Self::get_or_parse but the caller specifies which provider
the file belongs to — the parser skips content-based detection, so
metadata sentinels at the top of a Claude session (permission-mode,
file-history-snapshot) cannot cause the file to be mis-filed under a
different provider.
§Errors
Returns an error if the file’s metadata cannot be read or if parsing the
session file as provider fails.
Sourcepub fn cleanup_stale(&self)
pub fn cleanup_stale(&self)
Removes entries for non-existent files (manual cleanup).
With LRU eviction, stale entries are naturally removed over time, so this is typically not needed in production.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Returns cache statistics for monitoring and debugging.
estimated_memory_kb is a real sum of per-entry sizes captured by
estimate_analysis_bytes at insertion time.
Sourcepub fn invalidate<P: AsRef<Path>>(&self, path: P)
pub fn invalidate<P: AsRef<Path>>(&self, path: P)
Removes a specific file from the cache.
Sourcepub fn get_cached_paths(&self) -> Vec<PathBuf>
pub fn get_cached_paths(&self) -> Vec<PathBuf>
Returns all currently cached file paths.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for FileParseCache
impl RefUnwindSafe for FileParseCache
impl Send for FileParseCache
impl Sync for FileParseCache
impl Unpin for FileParseCache
impl UnsafeUnpin for FileParseCache
impl UnwindSafe for FileParseCache
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> 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