pub struct Cache;Expand description
A cache implementation for storing data between requests.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn get<F, T>(key: &str, init: F) -> Result<T, Box<dyn Error>>
pub fn get<F, T>(key: &str, init: F) -> Result<T, Box<dyn Error>>
Retrieves a value from the cache by key, initializing it if not present.
If the value exists in the cache, deserializes and returns it. If not found, calls the initialization function, caches the result, and returns it.
§Arguments
key- The cache key to look upinit- Function to initialize the value if not found in cache
§Errors
Returns an error if serialization/deserialization fails or if the init function fails
Auto Trait Implementations§
impl Freeze for Cache
impl RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnwindSafe for Cache
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