Skip to main content

SharedEmbeddedStore

Struct SharedEmbeddedStore 

Source
pub struct SharedEmbeddedStore<const SHARDS: usize> { /* private fields */ }
Expand description

Cloneable, lock-striped embedded cache handle.

SharedEmbeddedStore is the embedded mode for applications that want to clone one cache handle into many workers while still allowing each worker to reach every key. It uses the same EmbeddedShard storage primitive as crate::storage::EmbeddedStore, but stores stripes in an Arc so clones are cheap and route to cache-padded shard locks.

use fast_cache::storage::{SharedEmbeddedConfig, SharedEmbeddedStore};

let _ = SharedEmbeddedStore::<3>::new(SharedEmbeddedConfig::default());

Implementations§

Source§

impl<const SHARDS: usize> SharedEmbeddedStore<SHARDS>

Source

pub fn new(config: SharedEmbeddedConfig) -> Self

Creates a cloneable shared embedded store with SHARDS lock stripes.

Source

pub const fn shard_count(&self) -> usize

Returns the number of cache stripes.

Source

pub fn route_mode(&self) -> EmbeddedRouteMode

Returns the configured route mode.

Source

pub fn route_key(&self, key: &[u8]) -> EmbeddedKeyRoute

Computes the route for a key.

Source

pub fn route_session(&self, session_prefix: &[u8]) -> EmbeddedSessionRoute

Computes the route for a session prefix.

Source§

impl<const SHARDS: usize> SharedEmbeddedStore<SHARDS>

Source

pub fn get(&self, key: &[u8]) -> Option<Ref<'_>>

Returns a borrowed value guard for key.

Source

pub fn get_mut(&self, key: &[u8]) -> Option<RefMut<'_>>

Returns a mutable guard for key.

Source

pub fn contains_key(&self, key: &[u8]) -> bool

Returns true when key is present in point-key storage.

Source

pub fn insert(&self, key: SharedBytes, value: SharedBytes)

Inserts or replaces a point-key value without a TTL.

Source

pub fn insert_with_ttl( &self, key: SharedBytes, value: SharedBytes, ttl_ms: Option<u64>, )

Inserts or replaces a point-key value with an optional relative TTL.

ttl_ms is measured from the current Unix time in milliseconds. Passing None keeps the no-TTL hot path.

Source

pub fn insert_slice(&self, key: &[u8], value: &[u8])

Inserts or replaces a point-key value from borrowed byte slices.

Source

pub fn insert_slice_with_ttl( &self, key: &[u8], value: &[u8], ttl_ms: Option<u64>, )

Inserts or replaces a point-key value from borrowed bytes with an optional relative TTL.

ttl_ms is measured from the current Unix time in milliseconds. Passing None keeps the no-TTL hot path.

Source

pub fn remove(&self, key: &[u8]) -> Option<SharedBytes>

Removes a point-key value and returns the stored bytes when present.

Source

pub fn entry(&self, key: SharedBytes) -> Entry<'_>

Locks the routed stripe and returns an occupied or vacant entry.

Source§

impl<const SHARDS: usize> SharedEmbeddedStore<SHARDS>

Source

pub fn get_session(&self, session_prefix: &[u8], key: &[u8]) -> Option<Ref<'_>>

Returns a borrowed session value guard.

Source

pub fn set_session(&self, session_prefix: &[u8], key: &[u8], value: &[u8])

Inserts or replaces a session-scoped value without a TTL.

Trait Implementations§

Source§

impl<const SHARDS: usize> Clone for SharedEmbeddedStore<SHARDS>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const SHARDS: usize> Debug for SharedEmbeddedStore<SHARDS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const SHARDS: usize> Freeze for SharedEmbeddedStore<SHARDS>

§

impl<const SHARDS: usize> !RefUnwindSafe for SharedEmbeddedStore<SHARDS>

§

impl<const SHARDS: usize> Send for SharedEmbeddedStore<SHARDS>

§

impl<const SHARDS: usize> Sync for SharedEmbeddedStore<SHARDS>

§

impl<const SHARDS: usize> Unpin for SharedEmbeddedStore<SHARDS>

§

impl<const SHARDS: usize> UnsafeUnpin for SharedEmbeddedStore<SHARDS>

§

impl<const SHARDS: usize> !UnwindSafe for SharedEmbeddedStore<SHARDS>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more