pub struct CompiledComponentCache { /* private fields */ }Expand description
Cache for compiled WebAssembly components.
Provides both in-memory and optional disk caching. Components are
keyed by ComponentTypeId (SHA-256 of the binary).
Thread-safe: uses RwLock for concurrent read access.
§COLD PATH — all operations are during pipeline setup.
§Examples
use torvyn_engine::CompiledComponentCache;
let cache = CompiledComponentCache::new(None);
assert_eq!(cache.len(), 0);Implementations§
Source§impl CompiledComponentCache
impl CompiledComponentCache
Sourcepub fn new(disk_dir: Option<PathBuf>) -> Self
pub fn new(disk_dir: Option<PathBuf>) -> Self
Create a new cache with an optional disk cache directory.
§COLD PATH
Sourcepub fn compute_type_id(bytes: &[u8]) -> ComponentTypeId
pub fn compute_type_id(bytes: &[u8]) -> ComponentTypeId
Compute the ComponentTypeId for a component binary.
Uses SHA-256 to produce a deterministic content hash.
§COLD PATH
§Examples
use torvyn_engine::CompiledComponentCache;
let id = CompiledComponentCache::compute_type_id(b"hello");
assert_eq!(id.as_bytes().len(), 32);Sourcepub fn get<E: WasmEngine>(
&self,
type_id: &ComponentTypeId,
engine: &E,
) -> Result<Option<CompiledComponent>, EngineError>
pub fn get<E: WasmEngine>( &self, type_id: &ComponentTypeId, engine: &E, ) -> Result<Option<CompiledComponent>, EngineError>
Sourcepub fn insert<E: WasmEngine>(
&self,
type_id: ComponentTypeId,
compiled: CompiledComponent,
engine: &E,
)
pub fn insert<E: WasmEngine>( &self, type_id: ComponentTypeId, compiled: CompiledComponent, engine: &E, )
Insert a compiled component into the cache.
§COLD PATH
Stores in memory. If disk caching is enabled, also writes to disk (failures are non-fatal).
Sourcepub fn compile_or_get<E: WasmEngine>(
&self,
bytes: &[u8],
engine: &E,
) -> Result<(ComponentTypeId, CompiledComponent), EngineError>
pub fn compile_or_get<E: WasmEngine>( &self, bytes: &[u8], engine: &E, ) -> Result<(ComponentTypeId, CompiledComponent), EngineError>
Compile a component with caching.
Checks the cache first. If not found, compiles the component and inserts it into the cache.
§COLD PATH
Auto Trait Implementations§
impl !Freeze for CompiledComponentCache
impl !RefUnwindSafe for CompiledComponentCache
impl Send for CompiledComponentCache
impl Sync for CompiledComponentCache
impl Unpin for CompiledComponentCache
impl UnsafeUnpin for CompiledComponentCache
impl !UnwindSafe for CompiledComponentCache
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> 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