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> 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