pub struct SendCache { /* private fields */ }
Expand description
Holds arbitrary query results which are namespaced by arbitrary scope types. Usually used
through SharedSendCache::cache_with
and SharedSendCache::gc
.
§Query types
Note: the types referenced in this documentation are only visible on individual methods, as
SendCache
is not itself a generic type.
Storage is sharded by the type of the query. The type of a query has three parts:
The query scope is the value which indexes the storage for a particular query type, it has the
bound Scope: 'static + Eq + Hash + Send
.
Each Scope
corresponds to at most a single Input: 'static + Send
and a single Output: 'static + Send
value at any given time.
§Reading stored values
See SendCache::get
which accepts borrowed forms of Scope
and Input
: Key
and Arg
respectively. Arg
must satisfy PartialEq<Input>
to determine
whether to return a stored output.
§Garbage Collection
Each time SendCache::gc
is called it removes any values which haven’t been
referenced since the prior call.
After each GC, all values still in the cache are marked garbage. They are marked live again when
inserted with SendCache::store
or read with
SendCache::get
.
Implementations§
Source§impl SendCache
impl SendCache
Sourcepub fn get<'k, Key, Scope, Arg, Input, Output>(
&self,
key: &'k Key,
arg: &Arg,
) -> Result<&Output, CacheMiss<'k, Key, Scope, Input, Output>>
pub fn get<'k, Key, Scope, Arg, Input, Output>( &self, key: &'k Key, arg: &Arg, ) -> Result<&Output, CacheMiss<'k, Key, Scope, Input, Output>>
Return a reference to a query’s stored output if a result is stored and arg
equals the
previously-stored Input
. If a reference is returned, the stored input/output
is marked as a root and will not be GC’d the next call.
If no reference is found, a CacheMiss
is returned. Call CacheMiss::init
to get
a CacheEntry
to pass to SendCache::store
.
Sourcepub fn store<Key, Scope, Input, Output>(
&mut self,
entry: CacheEntry<'_, Key, Scope, Input, Output>,
)
pub fn store<Key, Scope, Input, Output>( &mut self, entry: CacheEntry<'_, Key, Scope, Input, Output>, )
Stores a fresh CacheEntry
whose input/output will not be GC’d at the next call.
Call SendCache::get
to get a CacheMiss
and CacheMiss::init
to get a
CacheEntry
.
Trait Implementations§
impl RefUnwindSafe for SendCache
impl UnwindSafe for SendCache
Auto Trait Implementations§
impl Freeze for SendCache
impl Send for SendCache
impl !Sync for SendCache
impl Unpin for SendCache
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.