pub struct InMemoryStore<V>{ /* private fields */ }Expand description
In-process Store<V> backed by a HashMap keyed by
(rendered_namespace, key). Cheap to clone — internal state is
Arc<Mutex<...>>-shared.
TTL is honoured: entries written via
Store::put_with_options with a non-None ttl are dropped
from get / list results once their absolute expiry passes.
The sweep (Store::evict_expired) cleans the map structure;
callers may run it from a periodic graph if memory pressure
matters.
Implementations§
Source§impl<V> InMemoryStore<V>
impl<V> InMemoryStore<V>
Sourcepub fn new() -> InMemoryStore<V>
pub fn new() -> InMemoryStore<V>
Empty store.
Sourcepub fn total_entries(&self) -> usize
pub fn total_entries(&self) -> usize
Total entry count across all namespaces, including not-yet-
swept-but-expired ones. Useful for tests; production callers
should run Store::evict_expired first if they care about
the live count.
Trait Implementations§
Source§impl<V> Clone for InMemoryStore<V>
impl<V> Clone for InMemoryStore<V>
Source§fn clone(&self) -> InMemoryStore<V>
fn clone(&self) -> InMemoryStore<V>
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 moreSource§impl<V> Default for InMemoryStore<V>
impl<V> Default for InMemoryStore<V>
Source§fn default() -> InMemoryStore<V>
fn default() -> InMemoryStore<V>
Returns the “default value” for a type. Read more
Source§impl<V> Store<V> for InMemoryStore<V>
impl<V> Store<V> for InMemoryStore<V>
Source§fn put_with_options<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
value: V,
options: PutOptions,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
fn put_with_options<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
value: V,
options: PutOptions,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
Insert or replace
value at (ns, key) with the supplied
per-write options (TTL, future fields). This is the only
required write — Self::put is a thin convenience that
delegates here.Source§fn get<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
fn get<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
Look up
(ns, key). Returns None if absent or expired.Source§fn delete<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
fn delete<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
Delete
(ns, key). Idempotent — deleting an absent key
succeeds.Source§fn list<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
prefix: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
fn list<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
prefix: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
InMemoryStore<V>: 'async_trait,
List keys under
ns whose names start with prefix (or all
keys if prefix is None). Order is unspecified.Source§fn list_namespaces<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
prefix: &'life2 NamespacePrefix,
) -> Pin<Box<dyn Future<Output = Result<Vec<Namespace>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStore<V>: 'async_trait,
fn list_namespaces<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
prefix: &'life2 NamespacePrefix,
) -> Pin<Box<dyn Future<Output = Result<Vec<Namespace>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStore<V>: 'async_trait,
Source§fn evict_expired<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStore<V>: 'async_trait,
fn evict_expired<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStore<V>: 'async_trait,
Sweep expired entries. Returns the number of rows removed.
Default impl returns
Ok(0) — only backends that natively
track TTL implement this. Operators schedule it on a timer
(or trigger from cron / periodic graph) to bound store
growth in deployments where the store does not auto-expire
(e.g. plain put into Postgres without a TTL trigger).Source§fn put<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn put<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 ExecutionContext,
ns: &'life2 Namespace,
key: &'life3 str,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Insert or replace
value at (ns, key) with default options
(no TTL). The default impl delegates to
Self::put_with_options — backends only need to provide one.Auto Trait Implementations§
impl<V> Freeze for InMemoryStore<V>
impl<V> !RefUnwindSafe for InMemoryStore<V>
impl<V> Send for InMemoryStore<V>
impl<V> Sync for InMemoryStore<V>
impl<V> Unpin for InMemoryStore<V>
impl<V> UnsafeUnpin for InMemoryStore<V>
impl<V> !UnwindSafe for InMemoryStore<V>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestCreates a shared type from an unshared type.