pub struct KVCacheManager { /* private fields */ }Expand description
Main KV cache management engine
Implementations§
Source§impl KVCacheManager
impl KVCacheManager
Sourcepub fn new(config: KVCacheConfig, database: Arc<MemoryDatabase>) -> Result<Self>
pub fn new(config: KVCacheConfig, database: Arc<MemoryDatabase>) -> Result<Self>
Create a new KV cache manager
Sourcepub async fn process_conversation(
&mut self,
session_id: &str,
messages: &[Message],
current_kv_entries: &[KVEntry],
current_cache_size_bytes: usize,
max_cache_size_bytes: usize,
) -> Result<CacheProcessingResult>
pub async fn process_conversation( &mut self, session_id: &str, messages: &[Message], current_kv_entries: &[KVEntry], current_cache_size_bytes: usize, max_cache_size_bytes: usize, ) -> Result<CacheProcessingResult>
Process a conversation and manage cache
Sourcepub fn should_clear_by_conversation(&self, conversation_count: usize) -> bool
pub fn should_clear_by_conversation(&self, conversation_count: usize) -> bool
Check if cache needs to be cleared based on conversation count
Sourcepub fn should_clear_by_memory(
&self,
current_usage_bytes: usize,
max_memory_bytes: usize,
) -> bool
pub fn should_clear_by_memory( &self, current_usage_bytes: usize, max_memory_bytes: usize, ) -> bool
Check if cache needs to be cleared based on memory usage
Sourcepub async fn clear_cache(
&mut self,
session_id: &str,
current_entries: &[KVEntry],
reason: ClearReason,
) -> Result<CacheClearResult>
pub async fn clear_cache( &mut self, session_id: &str, current_entries: &[KVEntry], reason: ClearReason, ) -> Result<CacheClearResult>
Clear KV cache intelligently
Sourcepub async fn retrieve_context(
&mut self,
session_id: &str,
query: &str,
current_cache_entries: &[KVEntry],
) -> Result<RetrievalResult>
pub async fn retrieve_context( &mut self, session_id: &str, query: &str, current_cache_entries: &[KVEntry], ) -> Result<RetrievalResult>
Retrieve relevant context from all tiers
Sourcepub fn get_statistics(&self) -> &CacheStatistics
pub fn get_statistics(&self) -> &CacheStatistics
Get cache statistics
Sourcepub fn get_session_state(&self, session_id: &str) -> Option<&SessionCacheState>
pub fn get_session_state(&self, session_id: &str) -> Option<&SessionCacheState>
Get session state
Sourcepub fn get_all_session_states(&self) -> &HashMap<String, SessionCacheState>
pub fn get_all_session_states(&self) -> &HashMap<String, SessionCacheState>
Get all session states
Sourcepub async fn restore_from_snapshot(
&mut self,
session_id: &str,
snapshot_id: i64,
) -> Result<Vec<KVEntry>>
pub async fn restore_from_snapshot( &mut self, session_id: &str, snapshot_id: i64, ) -> Result<Vec<KVEntry>>
Restore cache from snapshot
Sourcepub async fn manual_clear_cache(
&mut self,
session_id: &str,
current_entries: &[KVEntry],
) -> Result<CacheClearResult>
pub async fn manual_clear_cache( &mut self, session_id: &str, current_entries: &[KVEntry], ) -> Result<CacheClearResult>
Manual cache clear (for testing or admin purposes)
Sourcepub async fn perform_maintenance(&mut self) -> Result<MaintenanceResult>
pub async fn perform_maintenance(&mut self) -> Result<MaintenanceResult>
Check cache health and perform maintenance if needed
Sourcepub fn export_statistics(&self) -> CacheStatisticsExport
pub fn export_statistics(&self) -> CacheStatisticsExport
Export cache statistics
Sourcepub fn get_config(&self) -> &KVCacheConfig
pub fn get_config(&self) -> &KVCacheConfig
Get configuration
Sourcepub fn update_config(&mut self, config: KVCacheConfig)
pub fn update_config(&mut self, config: KVCacheConfig)
Update configuration
Sourcepub fn cache_scorer(&self) -> &CacheEntryScorer
pub fn cache_scorer(&self) -> &CacheEntryScorer
Get cache scorer reference
Sourcepub fn cache_scorer_mut(&mut self) -> &mut CacheEntryScorer
pub fn cache_scorer_mut(&mut self) -> &mut CacheEntryScorer
Get mutable cache scorer reference
Sourcepub fn reset_statistics(&mut self)
pub fn reset_statistics(&mut self)
Reset statistics
Auto Trait Implementations§
impl Freeze for KVCacheManager
impl !RefUnwindSafe for KVCacheManager
impl Send for KVCacheManager
impl Sync for KVCacheManager
impl Unpin for KVCacheManager
impl !UnwindSafe for KVCacheManager
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
Mutably borrows from an owned value. Read more
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>
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 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>
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