pub enum WithCacheOption {
None,
All,
Specific(HashMap<String, WithCacheConfig>),
}Expand description
PHP options['with_cache'] 的三种形态
对齐 PHP withCache($relation, $key, $expire, $tag) 行为:
// 1. 不缓存(false 或未设置)
$this->options['with_cache'] = false;
// 2. 全部关联缓存(true)
if (true === $relation || is_numeric($relation)) {
$this->options['with_cache'] = $relation;
}
// 3. 指定关联缓存
$this->options['with_cache'][$relation] = [$key, $expire, $tag];§变体
WithCacheOption::None:对齐 PHPwith_cache = false或未设置(不缓存)WithCacheOption::All:对齐 PHPwith_cache = true(全部关联都缓存)WithCacheOption::Specific:对齐 PHPwith_cache = [$name => [$key, $expire, $tag]]
§示例
ⓘ
use sz_rust_core::relation::cache::{WithCacheOption, WithCacheConfig};
// 全部关联缓存(对齐 PHP withCache(true))
let opt = WithCacheOption::All;
assert!(opt.is_enabled());
// 指定关联缓存(对齐 PHP withCache('orders', true, 3600, null))
let mut specific = std::collections::HashMap::new();
specific.insert("orders".to_string(), WithCacheConfig::default());
let opt = WithCacheOption::Specific(specific);
assert!(opt.is_enabled());
// 不缓存(对齐 PHP withCache(false))
let opt = WithCacheOption::None;
assert!(!opt.is_enabled());Variants§
None
不缓存(对齐 PHP with_cache = false 或未设置)
All
全部关联都缓存(对齐 PHP with_cache = true)
Specific(HashMap<String, WithCacheConfig>)
指定关联缓存(对齐 PHP with_cache = [$name => [$key, $expire, $tag]])
Implementations§
Source§impl WithCacheOption
impl WithCacheOption
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
是否启用缓存
Sourcepub fn is_specific(&self) -> bool
pub fn is_specific(&self) -> bool
是否为指定关联缓存
Sourcepub fn get_config(&self, relation_name: &str) -> Option<&WithCacheConfig>
pub fn get_config(&self, relation_name: &str) -> Option<&WithCacheConfig>
获取指定关联的缓存配置
返回 Some(&WithCacheConfig) 如果:
- 当前为
All(返回一个默认配置,对齐 PHP 全部关联使用相同默认配置) - 当前为
Specific且包含指定关联名
返回 None 如果:
- 当前为
None - 当前为
Specific但不包含指定关联名
Trait Implementations§
Source§impl Clone for WithCacheOption
impl Clone for WithCacheOption
Source§fn clone(&self) -> WithCacheOption
fn clone(&self) -> WithCacheOption
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WithCacheOption
impl Debug for WithCacheOption
Source§impl Default for WithCacheOption
impl Default for WithCacheOption
Source§fn default() -> WithCacheOption
fn default() -> WithCacheOption
Returns the “default value” for a type. Read more
impl Eq for WithCacheOption
Source§impl PartialEq for WithCacheOption
impl PartialEq for WithCacheOption
impl StructuralPartialEq for WithCacheOption
Auto Trait Implementations§
impl Freeze for WithCacheOption
impl RefUnwindSafe for WithCacheOption
impl Send for WithCacheOption
impl Sync for WithCacheOption
impl Unpin for WithCacheOption
impl UnsafeUnpin for WithCacheOption
impl UnwindSafe for WithCacheOption
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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