Skip to main content

FileParseCache

Struct FileParseCache 

Source
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

Source

pub fn new() -> Self

Creates a new LRU cache with capacity from constants::capacity::FILE_CACHE_SIZE.

Source

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:

  1. Check cache hit with read-only peek (no lock contention)
  2. If valid, promote entry to front with write lock
  3. 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.

Source

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.

Source

pub fn clear(&self)

Clears all entries from the cache.

Source

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.

Source

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.

Source

pub fn invalidate<P: AsRef<Path>>(&self, path: P)

Removes a specific file from the cache.

Source

pub fn get_cached_paths(&self) -> Vec<PathBuf>

Returns all currently cached file paths.

Trait Implementations§

Source§

impl Default for FileParseCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more