pub struct MultiLevelCacheDriver { /* private fields */ }Expand description
多级缓存驱动(对齐 PHP think-cache 多驱动场景)
PHP think-cache 本身没有显式的 MultiLevelCache 概念,但业务层常通过
Cache::store('redis') / Cache::store('file') 切换驱动。本驱动封装
sz_rust_orm_facade::MultiLevelCache,提供 L1(内存)→ L2(Redis)级联查询:
get:从高到低查询,命中后回填低层(带 TTL 保留)set:写入所有层级delete:删除所有层级has:任一层级存在即返回 trueclear:清空所有层级inc/dec:委托到第一层(最高级),读取→加减→写回
§使用示例
ⓘ
use sz_rust_cache_facade::{MultiLevelCacheDriver, MemoryCacheDriver};
use sz_rust_orm_facade::MemoryCache;
let l1 = MemoryCache::new();
let l2 = MemoryCache::with_ttl(std::time::Duration::from_secs(60));
let driver = MultiLevelCacheDriver::new()
.add_level(Box::new(l1))
.add_level(Box::new(l2));Implementations§
Source§impl MultiLevelCacheDriver
impl MultiLevelCacheDriver
Sourcepub fn add_level(self, cache: Box<dyn InnerCache>) -> Self
pub fn add_level(self, cache: Box<dyn InnerCache>) -> Self
添加缓存层级(链式调用,先添加的优先级高)
对齐 sz_rust_orm_facade::MultiLevelCache::add_cache
Sourcepub fn inner(&self) -> &MultiLevelCache
pub fn inner(&self) -> &MultiLevelCache
获取底层 MultiLevelCache 引用(用于 ttl 等底层查询)
Trait Implementations§
Source§impl CacheDriver for MultiLevelCacheDriver
impl CacheDriver for MultiLevelCacheDriver
Source§fn set_raw(
&self,
key: &str,
value: Vec<u8>,
ttl: Option<Duration>,
) -> Result<(), CacheError>
fn set_raw( &self, key: &str, value: Vec<u8>, ttl: Option<Duration>, ) -> Result<(), CacheError>
写入缓存原始字节
Source§fn inc(&self, key: &str, step: i64) -> Result<i64, CacheError>
fn inc(&self, key: &str, step: i64) -> Result<i64, CacheError>
自增(对齐 PHP
inc,不经序列化层) Read moreSource§fn dec(&self, key: &str, step: i64) -> Result<i64, CacheError>
fn dec(&self, key: &str, step: i64) -> Result<i64, CacheError>
自减(对齐 PHP
dec,不经序列化层) Read moreSource§fn tag_append(&self, tag_key: &str, cache_key: &str) -> Result<(), CacheError>
fn tag_append(&self, tag_key: &str, cache_key: &str) -> Result<(), CacheError>
Auto Trait Implementations§
impl !RefUnwindSafe for MultiLevelCacheDriver
impl !UnwindSafe for MultiLevelCacheDriver
impl Freeze for MultiLevelCacheDriver
impl Send for MultiLevelCacheDriver
impl Sync for MultiLevelCacheDriver
impl Unpin for MultiLevelCacheDriver
impl UnsafeUnpin for MultiLevelCacheDriver
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