[−][src]Struct dyn_cache::local::LocalCache
Holds arbitrary query results which are namespaced by arbitrary scope types. Usually used
through SharedLocalCache::cache_with and SharedLocalCache::gc.
Query types
Note: the types referenced in this documentation are only visible on individual methods, as
LocalCacheis 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.
Each Scope corresponds to at most a single Input: 'static
and a single Output: 'static value at any given time.
Reading stored values
See LocalCache::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 LocalCache::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 LocalCache::store or read with
LocalCache::get.
Implementations
impl LocalCache[src]
pub fn get<'k, Key: ?Sized, Scope, Arg: ?Sized, Input, Output>(
&self,
key: &'k Key,
arg: &Arg
) -> Result<&Output, CacheMiss<'k, Key, Scope, Input, Output>> where
Key: Eq + Hash + ToOwned<Owned = Scope>,
Scope: 'static + Borrow<Key> + Eq + Hash,
Arg: PartialEq<Input> + ToOwned<Owned = Input>,
Input: 'static + Borrow<Arg>,
Output: 'static, [src]
&self,
key: &'k Key,
arg: &Arg
) -> Result<&Output, CacheMiss<'k, Key, Scope, Input, Output>> where
Key: Eq + Hash + ToOwned<Owned = Scope>,
Scope: 'static + Borrow<Key> + Eq + Hash,
Arg: PartialEq<Input> + ToOwned<Owned = Input>,
Input: 'static + Borrow<Arg>,
Output: 'static,
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 LocalCache::store.
pub fn store<Key: ?Sized, Scope, Input, Output>(
&mut self,
entry: CacheEntry<'_, Key, Scope, Input, Output>
) where
Key: Eq + Hash + ToOwned<Owned = Scope>,
Scope: 'static + Borrow<Key> + Eq + Hash,
Input: 'static,
Output: 'static, [src]
&mut self,
entry: CacheEntry<'_, Key, Scope, Input, Output>
) where
Key: Eq + Hash + ToOwned<Owned = Scope>,
Scope: 'static + Borrow<Key> + Eq + Hash,
Input: 'static,
Output: 'static,
Stores a fresh CacheEntry whose input/output will not be GC'd at the next call.
Call LocalCache::get to get a CacheMiss and CacheMiss::init to get a
CacheEntry.
pub fn gc(&mut self)[src]
Drop any values which have not been marked alive since the last call to this method.
Trait Implementations
impl Debug for LocalCache[src]
impl Default for LocalCache[src]
pub fn default() -> LocalCache[src]
impl From<LocalCache> for SharedLocalCache[src]
pub fn from(inner: LocalCache) -> Self[src]
impl RefUnwindSafe for LocalCache[src]
impl UnwindSafe for LocalCache[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> AsContext for T where
T: Debug + 'static, [src]
T: Debug + 'static,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Downcast for T where
T: Any, [src]
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>[src]
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>[src]
pub fn as_any(&self) -> &(dyn Any + 'static)[src]
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)[src]
impl<T> Erased for T
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,