pub struct NamespacedMemory { /* private fields */ }Expand description
Namespaced memory wrapper providing isolation and TTL support
§Architecture
┌─────────────────────────────────────────┐
│ NamespacedMemory │
├─────────────────────────────────────────┤
│ Namespace: "market" │
│ - btc_price → $43,200 (TTL: 5m) │
│ - eth_price → $2,300 (TTL: 5m) │
├─────────────────────────────────────────┤
│ Namespace: "news" │
│ - latest → "Fed announces..." (TTL: 1h) │
├─────────────────────────────────────────┤
│ Namespace: "analysis" │
│ - btc_signal → "BUY" (TTL: 30m) │
└─────────────────────────────────────────┘§Benefits
- Isolation: Each namespace is independent
- TTL: Automatic expiration of stale data
- Performance: Shared data avoids redundant computation
- Security: Namespaces prevent cross-contamination
Implementations§
Source§impl NamespacedMemory
impl NamespacedMemory
Sourcepub fn new(memory: Arc<MemoryManager>) -> Self
pub fn new(memory: Arc<MemoryManager>) -> Self
Create a new namespaced memory wrapper
Sourcepub async fn store(
&self,
namespace: &str,
key: &str,
value: &str,
ttl: Option<Duration>,
author: Option<String>,
) -> Result<()>
pub async fn store( &self, namespace: &str, key: &str, value: &str, ttl: Option<Duration>, author: Option<String>, ) -> Result<()>
Store a value in a specific namespace with optional TTL
§Arguments
namespace- Namespace for isolation (e.g., “market”, “news”, “analysis”)key- Unique key within the namespacevalue- Value to storettl- Optional time-to-live durationauthor- Optional author/source identifier
§Example
ⓘ
// Store market price with 5-minute TTL
memory.store(
"market",
"btc_price",
"$43,200",
Some(Duration::from_secs(300)),
Some("PriceAPI")
).await?;Sourcepub async fn read_with_metadata(
&self,
namespace: &str,
key: &str,
) -> Result<Option<MemoryEntry>>
pub async fn read_with_metadata( &self, namespace: &str, key: &str, ) -> Result<Option<MemoryEntry>>
Read with metadata (including timestamp, author, etc.)
Sourcepub async fn list_keys(&self, namespace: &str) -> Result<Vec<String>>
pub async fn list_keys(&self, namespace: &str) -> Result<Vec<String>>
List all keys in a namespace
Sourcepub async fn delete(&self, namespace: &str, key: &str) -> Result<()>
pub async fn delete(&self, namespace: &str, key: &str) -> Result<()>
Delete a key from a namespace
Sourcepub async fn clear_namespace(&self, namespace: &str) -> Result<()>
pub async fn clear_namespace(&self, namespace: &str) -> Result<()>
Clear all entries in a namespace
Auto Trait Implementations§
impl Freeze for NamespacedMemory
impl !RefUnwindSafe for NamespacedMemory
impl Send for NamespacedMemory
impl Sync for NamespacedMemory
impl Unpin for NamespacedMemory
impl !UnwindSafe for NamespacedMemory
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> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
Query the “status” flags for the
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
Set the “status” flags for the
self file descriptor. Read moreSource§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::RequestSource§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::Request