Skip to main content

Module cache

Module cache 

Source
Expand description

Query Cache for parsed SQL statements

This module provides a cache for previously parsed SQL queries, storing the parse tree to avoid the overhead of parsing the same query multiple times.

§Example

let cache = QueryCache::<()>::new(1000);

// First query - will be parsed and cached
if let Some(plan) = cache.get("SELECT * FROM users") {
    // Use cached plan
} else {
    // Parse and cache
    let stmt = parse(sql);
    cache.put(sql, stmt, false, 0);
}

// Second identical query - retrieved from cache
let plan = cache.get("SELECT * FROM users").unwrap();

Re-exports§

pub use crate::compiled_plan::CompiledCountDistinct;
pub use crate::compiled_plan::CompiledCountStar;
pub use crate::compiled_plan::CompiledExecution;
pub use crate::compiled_plan::CompiledInsert;
pub use crate::compiled_plan::CompiledPkDelete;
pub use crate::compiled_plan::CompiledPkLookup;
pub use crate::compiled_plan::CompiledPkUpdate;
pub use crate::compiled_plan::CompiledUpdateColumn;
pub use crate::compiled_plan::PkValueSource;
pub use crate::compiled_plan::UpdateValueSource;

Structs§

CacheStats
Cache statistics
CachedPlanRef
Lightweight reference to a cached plan for query execution. Contains only what’s needed to execute: the immutable statement and param info.
CachedQueryPlan
Represents a parsed and prepared statement stored in the cache
ParameterContract
Exact parameter shape owned by one parsed statement.
QueryCache
Query cache for parsed SQL statements

Constants§

DEFAULT_CACHE_SIZE
Default cache size (number of cached plans)