pub struct WorkingMemory { /* private fields */ }Expand description
Working memory - session-scoped KV store with TTL.
TigerStyle:
- Bounded capacity (~1MB)
- TTL-based expiration
- Explicit size tracking
- DST-compatible via set_clock_ms()
Implementations§
Source§impl WorkingMemory
impl WorkingMemory
Sourcepub fn with_config(config: WorkingMemoryConfig) -> Self
pub fn with_config(config: WorkingMemoryConfig) -> Self
Create a new working memory with custom configuration.
Sourcepub fn set_clock_ms(&mut self, ms: u64)
pub fn set_clock_ms(&mut self, ms: u64)
Set the internal clock (for DST).
TigerStyle: Explicit time control for simulation.
Sourcepub fn set(
&mut self,
key: &str,
value: &[u8],
ttl_ms: Option<u64>,
) -> Result<(), WorkingMemoryError>
pub fn set( &mut self, key: &str, value: &[u8], ttl_ms: Option<u64>, ) -> Result<(), WorkingMemoryError>
Set an entry with optional TTL.
If TTL is None, uses the default TTL from config. If key already exists, the entry is replaced and TTL is reset.
§Errors
Returns error if entry is too large, memory is full, or too many entries.
Sourcepub fn get(&self, key: &str) -> Option<&[u8]>
pub fn get(&self, key: &str) -> Option<&[u8]>
Get an entry by key.
Returns None if key doesn’t exist or entry is expired.
Sourcepub fn delete(&mut self, key: &str) -> bool
pub fn delete(&mut self, key: &str) -> bool
Delete an entry by key.
Returns true if entry existed (even if expired), false otherwise.
Sourcepub fn cleanup_expired(&mut self) -> usize
pub fn cleanup_expired(&mut self) -> usize
Remove all expired entries.
Returns the number of entries removed.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Get used bytes (keys + values).
Sourcepub fn available_bytes(&self) -> usize
pub fn available_bytes(&self) -> usize
Get available bytes.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Get entry count (including expired).
Sourcepub fn config(&self) -> &WorkingMemoryConfig
pub fn config(&self) -> &WorkingMemoryConfig
Get configuration.
Trait Implementations§
Source§impl Debug for WorkingMemory
impl Debug for WorkingMemory
Auto Trait Implementations§
impl Freeze for WorkingMemory
impl RefUnwindSafe for WorkingMemory
impl Send for WorkingMemory
impl Sync for WorkingMemory
impl Unpin for WorkingMemory
impl UnwindSafe for WorkingMemory
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