pub struct IndexingCache { /* private fields */ }Expand description
Cache for agent and workspace IDs during batch indexing.
Prevents N+1 database queries by caching the results of ensure_agent and ensure_workspace calls within a batch. This is per-batch and single-threaded, so no synchronization is needed.
§Usage
let mut cache = IndexingCache::new();
for conv in conversations {
let agent_id = cache.get_or_insert_agent(storage, &agent)?;
let workspace_id = cache.get_or_insert_workspace(storage, workspace)?;
// ... use agent_id and workspace_id
}§Rollback
Set environment variable CASS_SQLITE_CACHE=0 to bypass caching
and use direct DB calls (useful for debugging).
Implementations§
Source§impl IndexingCache
impl IndexingCache
Sourcepub fn is_enabled() -> bool
pub fn is_enabled() -> bool
Check if caching is enabled via environment variable. Returns true unless CASS_SQLITE_CACHE is set to “0” or “false”.
Sourcepub fn get_or_insert_agent<S>(
&mut self,
storage: &S,
agent: &Agent,
) -> Result<i64>where
S: IndexingCacheStorage + ?Sized,
pub fn get_or_insert_agent<S>(
&mut self,
storage: &S,
agent: &Agent,
) -> Result<i64>where
S: IndexingCacheStorage + ?Sized,
Get or insert an agent ID, using cache if available.
Returns the cached ID if present, otherwise calls ensure_agent and caches the result.
Sourcepub fn get_or_insert_workspace(
&mut self,
storage: &(impl IndexingCacheStorage + ?Sized),
path: &Path,
display_name: Option<&str>,
) -> Result<i64>
pub fn get_or_insert_workspace( &mut self, storage: &(impl IndexingCacheStorage + ?Sized), path: &Path, display_name: Option<&str>, ) -> Result<i64>
Get or insert a workspace ID, using cache if available.
Returns the cached ID if present, otherwise calls ensure_workspace and caches the result.
Sourcepub fn agent_count(&self) -> usize
pub fn agent_count(&self) -> usize
Number of cached agents.
Sourcepub fn workspace_count(&self) -> usize
pub fn workspace_count(&self) -> usize
Number of cached workspaces.
Trait Implementations§
Source§impl Debug for IndexingCache
impl Debug for IndexingCache
Source§impl Default for IndexingCache
impl Default for IndexingCache
Source§fn default() -> IndexingCache
fn default() -> IndexingCache
Auto Trait Implementations§
impl Freeze for IndexingCache
impl RefUnwindSafe for IndexingCache
impl Send for IndexingCache
impl Sync for IndexingCache
impl Unpin for IndexingCache
impl UnsafeUnpin for IndexingCache
impl UnwindSafe for IndexingCache
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().