pub struct CompilationCache { /* private fields */ }Expand description
Thread-safe LRU cache for compiled schemas.
§Design
- Fingerprinting: Uses SHA-256 hash of schema JSON for cache keys
- LRU eviction: Automatically evicts least-recently-used entries
- Thread-safe: All operations use interior mutability
§Memory Safety
- Hard LRU limit ensures bounded memory usage
- Default config: 100 entries (reasonable for most deployments)
§Example
use fraiseql_core::compiler::compilation_cache::{CompilationCache, CompilationCacheConfig};
use fraiseql_core::compiler::Compiler;
let cache = CompilationCache::new(CompilationCacheConfig::default());
let compiler = Compiler::new();
let schema_json = r#"{"types": [], "queries": []}"#;
// First compilation - cache miss
let compiled = cache.compile(&compiler, schema_json)?;
// Second compilation - cache hit
let compiled_cached = cache.compile(&compiler, schema_json)?;
Implementations§
Source§impl CompilationCache
impl CompilationCache
Sourcepub fn new(config: CompilationCacheConfig) -> Self
pub fn new(config: CompilationCacheConfig) -> Self
Create new compilation cache with configuration.
§Panics
Panics if cache is enabled but max_entries is 0.
Sourcepub fn compile(
&self,
compiler: &Compiler,
schema_json: &str,
) -> Result<Arc<CompiledSchema>>
pub fn compile( &self, compiler: &Compiler, schema_json: &str, ) -> Result<Arc<CompiledSchema>>
Compile schema with caching.
If cache is enabled and schema fingerprint matches a cached entry, returns the cached compiled schema. Otherwise, compiles the schema and stores result in cache.
§Arguments
compiler- Schema compilerschema_json- JSON schema from Python/TypeScript decorators
§Returns
Compiled schema (cached if possible)
Sourcepub fn metrics(&self) -> Result<CompilationCacheMetrics>
pub fn metrics(&self) -> Result<CompilationCacheMetrics>
Get current cache metrics.
Auto Trait Implementations§
impl Freeze for CompilationCache
impl RefUnwindSafe for CompilationCache
impl Send for CompilationCache
impl Sync for CompilationCache
impl Unpin for CompilationCache
impl UnsafeUnpin for CompilationCache
impl UnwindSafe for CompilationCache
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