pub struct CacheManager { /* private fields */ }Expand description
缓存驱动管理器(对齐 PHP think\Cache extends Manager)
PHP think\Cache 继承 think\Manager,提供多驱动支持:
$cache = new think\Cache();
$cache->store('file')->set('key', 'value');
$cache->store('redis')->set('key', 'value');本结构体提供等价的 Rust 抽象:
register_store(name, driver):注册命名驱动store(name):获取命名驱动default_store():获取默认驱动
Implementations§
Source§impl CacheManager
impl CacheManager
Sourcepub fn register_store(
&mut self,
name: impl Into<String>,
driver: Box<dyn CacheDriver>,
)
pub fn register_store( &mut self, name: impl Into<String>, driver: Box<dyn CacheDriver>, )
注册命名驱动
对齐 PHP Manager::createDriver(array $config) + $this->drivers[$name] = $driver。
§参数
name:驱动名(如"file"、"redis")driver:驱动实例
Sourcepub fn set_default(&mut self, name: impl Into<String>) -> Result<(), CacheError>
pub fn set_default(&mut self, name: impl Into<String>) -> Result<(), CacheError>
设置默认驱动名
对齐 PHP config/cache.php 中 'default' => 'redis'。
Sourcepub fn store(&self, name: &str) -> Result<&dyn CacheDriver, CacheError>
pub fn store(&self, name: &str) -> Result<&dyn CacheDriver, CacheError>
获取命名驱动
对齐 PHP Manager::store(string $name = null)。
Sourcepub fn default_store(&self) -> Result<&dyn CacheDriver, CacheError>
pub fn default_store(&self) -> Result<&dyn CacheDriver, CacheError>
获取默认驱动
对齐 PHP $cache->store()(默认驱动)。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CacheManager
impl !UnwindSafe for CacheManager
impl Freeze 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> 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