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. Uses parking_lot::Mutex
internally, so lock operations are infallible (no poison panics).
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 emitted by the authoring-language decorators
§Errors
Returns FraiseQLError if schema compilation fails.
Sourcepub fn metrics(&self) -> Result<CompilationCacheMetrics>
pub fn metrics(&self) -> Result<CompilationCacheMetrics>
Get current cache metrics.
§Errors
This function is currently infallible. The Result return type is
reserved for future implementations that may use fallible storage.
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
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