pub struct CacheKey { /* private fields */ }Expand description
Names one cached read: a name for what is read, plus the arguments its
answer depends on.
You rarely build one yourself. use_cached
and invalidate_cached derive it from the server function
and its arguments, so the key cannot miss an argument. Build one by hand
only for a read that is not a single server function call, for
use_cached_key:
use g3_cache::CacheKey;
let key = CacheKey::new("home_shelves").with("movie").with(3);
assert_eq!(key.name(), "home_shelves");invalidate_cached_name matches every key with a
given name; invalidate_cached_key matches one key
exactly.
Implementations§
Source§impl CacheKey
impl CacheKey
Sourcepub fn new(name: impl Into<Cow<'static, str>>) -> Self
pub fn new(name: impl Into<Cow<'static, str>>) -> Self
A key with no arguments yet. Add each thing the read depends on with
with.
Sourcepub fn with(self, part: impl Serialize) -> Self
pub fn with(self, part: impl Serialize) -> Self
Adds an argument the read depends on. Any Serialize value works;
it is stored as JSON.
§Panics
If part cannot be serialized to JSON (a map with non-string keys,
for example). That is a bug in the key, not a runtime condition.
Sourcepub fn of<F, Args>(server_fn: &F, args: &Args) -> Selfwhere
F: CacheableFn<Args>,
Args: Serialize,
pub fn of<F, Args>(server_fn: &F, args: &Args) -> Selfwhere
F: CacheableFn<Args>,
Args: Serialize,
The key for calling server_fn with args: the function’s path, and
the arguments as JSON. Arguments are a tuple, as for
use_cached: (), (id,),
(id, page).
§Panics
If server_fn is a closure; see CacheableFn.
Trait Implementations§
impl Eq for CacheKey
Source§impl Ord for CacheKey
impl Ord for CacheKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for CacheKey
impl PartialOrd for CacheKey
impl StructuralPartialEq for CacheKey
Auto Trait Implementations§
impl Freeze for CacheKey
impl RefUnwindSafe for CacheKey
impl Send for CacheKey
impl Sync for CacheKey
impl Unpin for CacheKey
impl UnsafeUnpin for CacheKey
impl UnwindSafe for CacheKey
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DependencyElement for T
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
key and return true if they are equal.