pub struct MemoryStore { /* private fields */ }Expand description
A process-local cache. Cloning shares one store, so it can be registered as application state and handed to every handler.
Implementations§
Source§impl MemoryStore
impl MemoryStore
pub fn new() -> Self
pub fn with_prefix(prefix: impl Into<String>) -> Self
Sourcepub fn with_options(prefix: impl Into<String>, sweep_every: Duration) -> Self
pub fn with_options(prefix: impl Into<String>, sweep_every: Duration) -> Self
Build a store with an explicit sweep interval.
The sweep is spawned only when a Tokio runtime is already running, so constructing a cache during boot — before the runtime exists — works and simply relies on lazy eviction until the process starts serving.
Sourcepub fn sweep(&self)
pub fn sweep(&self)
Remove expired entries now. The background sweep calls this; tests call it directly rather than waiting a minute.
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Cache for MemoryStore
impl Cache for MemoryStore
Source§fn driver(&self) -> &'static str
fn driver(&self) -> &'static str
The driver’s name, used in
cache.hit / cache.miss events and in
error messages. Telescope shows it as the store column.Source§fn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Json>>>
fn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Json>>>
Fetch a value, or
None when it is missing or expired. Read moreSource§fn put<'a>(
&'a self,
key: &'a str,
value: Json,
ttl: Duration,
) -> BoxFuture<'a, Result<()>>
fn put<'a>( &'a self, key: &'a str, value: Json, ttl: Duration, ) -> BoxFuture<'a, Result<()>>
Store a value that expires after
ttl. Read moreSource§fn forever<'a>(&'a self, key: &'a str, value: Json) -> BoxFuture<'a, Result<()>>
fn forever<'a>(&'a self, key: &'a str, value: Json) -> BoxFuture<'a, Result<()>>
Store a value with no expiry. It still goes away on
Cache::flush.Source§fn forget<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
fn forget<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
Remove a key. Returns whether something was actually there.
Source§fn increment<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>
fn increment<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>
Add
by to a counter, creating it at zero first. Returns the new value. Read moreSource§fn increment_within<'a>(
&'a self,
key: &'a str,
by: i64,
ttl: Duration,
) -> BoxFuture<'a, Result<i64>>
fn increment_within<'a>( &'a self, key: &'a str, by: i64, ttl: Duration, ) -> BoxFuture<'a, Result<i64>>
Increment a counter, giving it
ttl only when this call created it. Read moreSource§fn ttl<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Duration>>>
fn ttl<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Duration>>>
How long until a key expires:
None when it is missing or immortal. Read moreSource§fn has<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
fn has<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
Whether a live (unexpired) value exists.
Source§impl Clone for MemoryStore
impl Clone for MemoryStore
Source§fn clone(&self) -> MemoryStore
fn clone(&self) -> MemoryStore
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MemoryStore
impl RefUnwindSafe for MemoryStore
impl Send for MemoryStore
impl Sync for MemoryStore
impl Unpin for MemoryStore
impl UnsafeUnpin for MemoryStore
impl UnwindSafe for MemoryStore
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