pub struct CacheManager { /* private fields */ }Expand description
L1 缓存管理器:进程内 Ok(EvalResult) 缓存,字节权重预算驱逐,无 TTL。
Implementations§
Source§impl CacheManager
impl CacheManager
Sourcepub fn with_capacity_bytes(max_bytes: u64) -> Self
pub fn with_capacity_bytes(max_bytes: u64) -> Self
创建指定字节权重预算的缓存管理器(--cache-size N 按 4KB/条换算)。
Sourcepub fn get(&self, cf: &CanonicalForm) -> Option<EvalResult>
pub fn get(&self, cf: &CanonicalForm) -> Option<EvalResult>
查询缓存。命中返回 EvalResult 克隆,未命中返回 None。
Sourcepub fn insert(&self, cf: &CanonicalForm, result: &Result<EvalResult, CalcError>)
pub fn insert(&self, cf: &CanonicalForm, result: &Result<EvalResult, CalcError>)
写入缓存(仅成功结果;估算超过 MAX_CACHEABLE_BYTES 的大结果跳过写入)。
Sourcepub fn get_or_compute<F>(
&self,
cf: &CanonicalForm,
compute: F,
) -> Result<EvalResult, CalcError>
pub fn get_or_compute<F>( &self, cf: &CanonicalForm, compute: F, ) -> Result<EvalResult, CalcError>
查询或计算:并发相同 key 仅有 leader 执行 compute,错误原样传播且不缓存。
Sourcepub fn entry_count(&self) -> u64
pub fn entry_count(&self) -> u64
当前缓存条目数(先同步执行 moka 待维护任务,保证读取时点准确)。
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CacheManager
impl !RefUnwindSafe for CacheManager
impl !UnwindSafe for CacheManager
impl Forget for CacheManager
impl Move for CacheManager
impl Send for CacheManager
impl Sync for CacheManager
impl Unpin for CacheManager
impl UnsafeUnpin for CacheManager
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.