pub struct L1Cache<T> { /* private fields */ }Expand description
L1 一级缓存(Session 级别 Identity Map)
- Identity Map:相同主键返回相同
Arc<T>引用 - LRU 淘汰:超过
capacity时淘汰最久未使用条目 - 无锁统计:
AtomicU64原子计数,并发安全 - Session 绑定:非
Send + Sync,不跨线程共享(Session 内使用)
泛型参数 T 为缓存值类型,主键类型固定为 i64(与 Model::PrimaryKey 对齐)。
Implementations§
Source§impl<T> L1Cache<T>
impl<T> L1Cache<T>
Sourcepub fn put(&mut self, key: i64, value: Arc<T>)
pub fn put(&mut self, key: i64, value: Arc<T>)
存入缓存项(Identity Map 语义:同主键返回同引用)
如果主键已存在,更新值并移到 LRU 尾部(最近使用)。 如果超过容量上限,淘汰 LRU 头部(最久未使用)条目。
Sourcepub fn get(&mut self, key: &i64) -> Option<Arc<T>>
pub fn get(&mut self, key: &i64) -> Option<Arc<T>>
查询缓存项(Identity Map 语义:同主键返回同 Arc 引用)
命中时更新 LRU 顺序(移到尾部),未命中时递增 miss 计数。
Sourcepub fn stats(&self) -> L1CacheStats
pub fn stats(&self) -> L1CacheStats
获取统计快照(无锁原子读取)
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for L1Cache<T>
impl<T> RefUnwindSafe for L1Cache<T>where
T: RefUnwindSafe,
impl<T> Send for L1Cache<T>
impl<T> Sync for L1Cache<T>
impl<T> Unpin for L1Cache<T>
impl<T> UnsafeUnpin for L1Cache<T>
impl<T> UnwindSafe for L1Cache<T>where
T: RefUnwindSafe,
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> 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