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§
Sourcepub fn new(config: SharedEmbeddedConfig) -> Self
pub fn new(config: SharedEmbeddedConfig) -> Self
Creates a cloneable shared embedded store with SHARDS lock stripes.
Sourcepub const fn shard_count(&self) -> usize
pub const fn shard_count(&self) -> usize
Returns the number of cache stripes.
Sourcepub fn route_mode(&self) -> EmbeddedRouteMode
pub fn route_mode(&self) -> EmbeddedRouteMode
Returns the configured route mode.
Sourcepub fn route_key(&self, key: &[u8]) -> EmbeddedKeyRoute
pub fn route_key(&self, key: &[u8]) -> EmbeddedKeyRoute
Computes the route for a key.
Sourcepub fn route_session(&self, session_prefix: &[u8]) -> EmbeddedSessionRoute
pub fn route_session(&self, session_prefix: &[u8]) -> EmbeddedSessionRoute
Computes the route for a session prefix.
Sourcepub fn contains_key(&self, key: &[u8]) -> bool
pub fn contains_key(&self, key: &[u8]) -> bool
Returns true when key is present in point-key storage.
Sourcepub fn insert(&self, key: SharedBytes, value: SharedBytes)
pub fn insert(&self, key: SharedBytes, value: SharedBytes)
Inserts or replaces a point-key value without a TTL.
Sourcepub fn insert_with_ttl(
&self,
key: SharedBytes,
value: SharedBytes,
ttl_ms: Option<u64>,
)
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.
Sourcepub fn insert_slice(&self, key: &[u8], value: &[u8])
pub fn insert_slice(&self, key: &[u8], value: &[u8])
Inserts or replaces a point-key value from borrowed byte slices.
Sourcepub fn insert_slice_with_ttl(
&self,
key: &[u8],
value: &[u8],
ttl_ms: Option<u64>,
)
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.
Sourcepub fn remove(&self, key: &[u8]) -> Option<SharedBytes>
pub fn remove(&self, key: &[u8]) -> Option<SharedBytes>
Removes a point-key value and returns the stored bytes when present.
Sourcepub fn entry(&self, key: SharedBytes) -> Entry<'_>
pub fn entry(&self, key: SharedBytes) -> Entry<'_>
Locks the routed stripe and returns an occupied or vacant entry.