pub struct ColumnarCache { /* private fields */ }Expand description
LRU cache for columnar table representations
Provides memory-bounded caching of columnar table data with automatic
eviction when the memory budget is exceeded. Tables are stored as Arc
to enable zero-copy sharing between queries.
§Memory Management
The cache tracks memory usage based on ColumnarTable::size_in_bytes().
When inserting a new entry would exceed the budget, the least recently
used entries are evicted until there’s sufficient space.
§Example
use vibesql_storage::columnar_cache::ColumnarCache;
// Create a cache with 256MB budget
let cache = ColumnarCache::new(256 * 1024 * 1024);
// Get or create columnar representation
if let Some(columnar) = cache.get("lineitem") {
// Use cached data
} else {
// Convert and cache
let columnar = table.scan_columnar()?;
cache.insert("lineitem", columnar);
}Implementations§
Source§impl ColumnarCache
impl ColumnarCache
Sourcepub fn get(&self, table_name: &str) -> Option<Arc<ColumnarTable>>
pub fn get(&self, table_name: &str) -> Option<Arc<ColumnarTable>>
Get a cached columnar table representation
Returns Some(Arc<ColumnarTable>) if the table is cached, None otherwise.
Accessing a cached entry marks it as recently used.
Table names are normalized for case-insensitive matching.
Sourcepub fn insert(
&self,
table_name: &str,
columnar: ColumnarTable,
) -> Arc<ColumnarTable>
pub fn insert( &self, table_name: &str, columnar: ColumnarTable, ) -> Arc<ColumnarTable>
Insert or update a columnar table in the cache
If the table is already cached, the existing entry is updated. If inserting would exceed the memory budget, least recently used entries are evicted until there’s sufficient space. Table names are normalized for case-insensitive matching.
§Arguments
table_name- Name of the tablecolumnar- The columnar table data to cache
§Returns
The Arc-wrapped columnar table (for immediate use)
Sourcepub fn invalidate(&self, table_name: &str)
pub fn invalidate(&self, table_name: &str)
Invalidate a cached table entry
Called when a table is modified (INSERT/UPDATE/DELETE) to ensure the cache doesn’t serve stale data. Table names are normalized for case-insensitive matching.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Get current memory usage in bytes
Sourcepub fn max_memory(&self) -> usize
pub fn max_memory(&self) -> usize
Get the memory budget in bytes