pub struct SemanticCache { /* private fields */ }Expand description
Semantic Query Cache
Intelligently caches query results and detects when new queries can be answered by filtering cached results.
Implementations§
Source§impl SemanticCache
impl SemanticCache
Sourcepub fn with_config(
max_size: usize,
ttl: Duration,
max_rows: usize,
max_global_rows: usize,
) -> Self
pub fn with_config( max_size: usize, ttl: Duration, max_rows: usize, max_global_rows: usize, ) -> Self
Create a semantic cache with custom configuration
Sourcepub fn with_config_and_byte_limit(
max_size: usize,
ttl: Duration,
max_rows: usize,
max_global_rows: usize,
max_global_bytes: usize,
) -> Self
pub fn with_config_and_byte_limit( max_size: usize, ttl: Duration, max_rows: usize, max_global_rows: usize, max_global_bytes: usize, ) -> Self
Create a semantic cache with explicit row and byte budgets.
Sourcepub fn lookup(
&self,
table_name: &str,
columns: &[String],
predicate: Option<&Expression>,
) -> CacheLookupResult
pub fn lookup( &self, table_name: &str, columns: &[String], predicate: Option<&Expression>, ) -> CacheLookupResult
Look up a query in the cache
Returns:
ExactHitif an identical query is cachedSubsumptionHitif a broader query is cached and can be filteredMissif no usable cache entry exists
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Current invalidation generation for guarding an in-flight query.
Sourcepub fn insert_if_generation(
&self,
expected_generation: u64,
table_name: &str,
columns: Vec<String>,
rows: Vec<Row>,
predicate: Option<Expression>,
)
pub fn insert_if_generation( &self, expected_generation: u64, table_name: &str, columns: Vec<String>, rows: Vec<Row>, predicate: Option<Expression>, )
Insert only if no invalidation occurred since query execution began.
Sourcepub fn invalidate_table(&self, table_name: &str)
pub fn invalidate_table(&self, table_name: &str)
Invalidate all cache entries for a table (O(1) operation)
Sourcepub fn stats(&self) -> SemanticCacheStatsSnapshot
pub fn stats(&self) -> SemanticCacheStatsSnapshot
Get cache statistics as a snapshot
Sourcepub fn filter_rows(
rows: Vec<Row>,
filter: &Expression,
columns: &[String],
_function_registry: &FunctionRegistry,
) -> Result<Vec<Row>>
pub fn filter_rows( rows: Vec<Row>, filter: &Expression, columns: &[String], _function_registry: &FunctionRegistry, ) -> Result<Vec<Row>>
Filter cached rows using a predicate
This is used when a subsumption match is found to filter the broader cached result down to the stricter query’s result.
CRITICAL: This function now returns Result to properly propagate compilation errors. Previously, compilation failures silently returned unfiltered data which was incorrect.