pub struct ModuleCache<T> {
inner: HashMap<CacheKey, Arc<T>>,
properties: Box<[&'static str]>,
}Expand description
A highly optimized cache that stores modules according to server configuration
Fields§
§inner: HashMap<CacheKey, Arc<T>>§properties: Box<[&'static str]>Implementations§
Source§impl<T> ModuleCache<T>
impl<T> ModuleCache<T>
Sourcepub fn new(properties: Vec<&'static str>) -> Self
pub fn new(properties: Vec<&'static str>) -> Self
Creates a cache that stores modules per specific properties
Sourcepub fn with_capacity(properties: Vec<&'static str>, capacity: usize) -> Self
pub fn with_capacity(properties: Vec<&'static str>, capacity: usize) -> Self
Creates a cache with custom initial capacity
Sourcepub fn get_or_init<F, E>(
&mut self,
config: &ServerConfiguration,
init_fn: F,
) -> Result<Arc<T>, E>
pub fn get_or_init<F, E>( &mut self, config: &ServerConfiguration, init_fn: F, ) -> Result<Arc<T>, E>
Obtains a module from cache, initializing if not present This is now O(1) average case instead of O(n)
Sourcepub fn get(&self, config: &ServerConfiguration) -> Option<Arc<T>>
pub fn get(&self, config: &ServerConfiguration) -> Option<Arc<T>>
Non-mutable variant that only retrieves from cache
Sourcepub fn get_or<F, E>(
&self,
config: &ServerConfiguration,
fallback_fn: F,
) -> Result<Arc<T>, E>
pub fn get_or<F, E>( &self, config: &ServerConfiguration, fallback_fn: F, ) -> Result<Arc<T>, E>
Gets a module from cache, or creates one with the fallback function without caching
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ModuleCache<T>
impl<T> RefUnwindSafe for ModuleCache<T>where
T: RefUnwindSafe,
impl<T> Send for ModuleCache<T>
impl<T> Sync for ModuleCache<T>
impl<T> Unpin for ModuleCache<T>
impl<T> UnsafeUnpin for ModuleCache<T>
impl<T> UnwindSafe for ModuleCache<T>where
T: RefUnwindSafe,
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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