FabricKvStore

Struct FabricKvStore 

Source
pub struct FabricKvStore { /* private fields */ }
Expand description

A key-value store backed by leased fabric resources.

The hot tier stores entries in a FabricHashMap over leased DRAM. Each entry tracks creation time, TTL, and access count. The tick() method evicts expired entries.

With the persistence feature, a cold tier backs overflow to block storage. On a hot-tier miss, the cold tier is scanned and matching entries are promoted back.

Implementations§

Source§

impl FabricKvStore

Source

pub fn put(&mut self, key: &[u8], value: &[u8]) -> Result<()>

Store a key-value pair with the default TTL.

Source

pub fn put_with_ttl( &mut self, key: &[u8], value: &[u8], ttl_secs: u32, ) -> Result<()>

Store a key-value pair with an explicit TTL in seconds.

Source

pub fn get(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>>

Retrieve a value by key.

Checks the hot tier first. On a miss (with persistence enabled), scans the cold tier and promotes the entry back to the hot tier.

Accessing a key refreshes its TTL (resets created_at to now).

Source

pub fn delete(&mut self, key: &[u8]) -> Result<bool>

Delete a key. Returns true if the key existed.

Source

pub fn exists(&mut self, key: &[u8]) -> Result<bool>

Check if a key exists (without reading the value).

Source

pub fn keys(&self) -> Result<Vec<Vec<u8>>>

Return all non-expired keys in the hot tier.

Source

pub fn ttl(&self, key: &[u8]) -> Result<Option<u32>>

Return the remaining TTL for a key in seconds, or None if the key does not exist or is expired.

Source

pub fn tick(&mut self) -> Result<usize>

Scan the hot tier and evict expired entries.

Source

pub fn put_struct<T: Serialize>(&mut self, key: &[u8], value: &T) -> Result<()>

Store a serializable struct as a value.

Source

pub fn put_struct_with_ttl<T: Serialize>( &mut self, key: &[u8], value: &T, ttl_secs: u32, ) -> Result<()>

Store a serializable struct with an explicit TTL.

Source

pub fn get_struct<T: DeserializeOwned>( &mut self, key: &[u8], ) -> Result<Option<T>>

Retrieve and deserialize a struct by key.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.