Skip to main content

DualCacheFF

Struct DualCacheFF 

Source
pub struct DualCacheFF<K, V, S = RandomState, Tls: TlsProvider = DefaultTls> {
Show 13 fields pub hasher: S, pub t1: Arc<T1<K, V>>, pub t2: Arc<T2<K, V>>, pub cache: Arc<Cache<K, V>>, pub cmd_tx: Arc<LossyQueue<Command<K, V>>>, pub hit_tx: Arc<LossyQueue<[usize; 64]>>, pub epoch: Arc<AtomicU32>, pub worker_states: Arc<[WorkerState]>, pub miss_buffers: Arc<[WorkerSlot<K, V>]>, pub daemon_tick: Arc<AtomicU64>, pub flush_tick_threshold: u64, pub is_cold_start: Arc<AtomicBool>, pub tls: Tls,
}

Fields§

§hasher: S§t1: Arc<T1<K, V>>§t2: Arc<T2<K, V>>§cache: Arc<Cache<K, V>>§cmd_tx: Arc<LossyQueue<Command<K, V>>>§hit_tx: Arc<LossyQueue<[usize; 64]>>§epoch: Arc<AtomicU32>§worker_states: Arc<[WorkerState]>

QSBR registry: one entry per thread slot.

§miss_buffers: Arc<[WorkerSlot<K, V>]>

Per-worker zero-lock batch buffers, indexed by WORKER_ID.

§daemon_tick: Arc<AtomicU64>

Daemon tick counter — shared with the Daemon thread. Workers read this (Relaxed) to implement time-based TLS flush.

§flush_tick_threshold: u64

Number of daemon_tick advances that correspond to ≈1 ms of real time.

§is_cold_start: Arc<AtomicBool>

Cold-start flag: Daemon sets this to false when capacity is reached.

§tls: Tls

The thread-local storage provider, injected at compile-time for zero overhead.

Implementations§

Source§

impl<K, V> DualCacheFF<K, V, RandomState, DefaultTls>
where K: Hash + Eq + Send + Sync + Clone + 'static, V: Send + Sync + Clone + 'static,

Source

pub fn new(config: Config) -> Self

Create a new DualCacheFF and automatically spawn the background Daemon.

Use this in std environments (servers, desktops).

Source§

impl<K, V, Tls> DualCacheFF<K, V, RandomState, Tls>
where K: Hash + Eq + Send + Sync + Clone + 'static, V: Send + Sync + Clone + 'static, Tls: TlsProvider + 'static,

Source

pub fn new_with_tls(config: Config, tls: Tls) -> Self

Create a new DualCacheFF and automatically spawn the background Daemon using a custom thread-local storage provider.

Source§

impl<K, V> DualCacheFF<K, V, RandomState, DefaultTls>
where K: Hash + Eq + Send + Sync + Clone + 'static, V: Send + Sync + Clone + 'static,

Source

pub fn new_with_spawner<Sp: DaemonSpawner + 'static>( config: Config, spawner: Sp, ) -> Self

Create a new DualCacheFF and automatically spawn the background Daemon using a custom spawner.

Source

pub fn new_headless(config: Config) -> (Self, Daemon<K, V, RandomState>)

Create a DualCacheFF and its Daemon without spawning any thread.

§std mode

Prefer DualCacheFF::new() which spawns the daemon automatically.

§no_std / RTOS mode

Use new_headless() to obtain both the cache handle and the daemon. Schedule daemon.run() on a dedicated RTOS task:

let (cache, daemon) = DualCacheFF::new_headless(config);
rtos::spawn_task(|| daemon.run()); // RTOS-specific API
Source§

impl<K, V, Tls> DualCacheFF<K, V, RandomState, Tls>
where K: Hash + Eq + Send + Sync + Clone + 'static, V: Send + Sync + Clone + 'static, Tls: TlsProvider + 'static,

Source

pub fn new_headless_with_tls( config: Config, tls: Tls, ) -> (Self, Daemon<K, V, RandomState>)

Create a DualCacheFF and its Daemon with a custom thread-local storage provider.

Source

pub fn new_with_tls_and_spawner<Sp: DaemonSpawner + 'static>( config: Config, tls: Tls, spawner: Sp, ) -> Self

Create a DualCacheFF and spawn its Daemon using both a custom TLS provider and custom spawner.

Source§

impl<K, V, S, Tls: TlsProvider> DualCacheFF<K, V, S, Tls>
where K: Hash + Eq + Send + Sync + Clone + 'static, V: Send + Sync + Clone + 'static, S: BuildHasher + Clone + Send + 'static,

Source

pub fn sync(&self)

Flush all pending TLS buffers and wait for the Daemon to process them.

Blocks via OneshotAck::wait() (spin-wait, safe in both std and no_std).

Source

pub fn get(&self, key: &K) -> Option<V>

Look up a key.

Hot-path order: T1 (L1 direct-map) → T2 (L2 direct-map) → Cache (L3). Records a hit signal into the TLS buffer for Daemon processing.

Source

pub fn insert(&self, key: K, value: V)

Insert a key-value pair.

§L1 Probation Filter (std only)

Items that appear only once in a TLS epoch are silently dropped. This prevents cache pollution from scan traffic. In no_std mode the filter is skipped and all items are forwarded.

§Task 6 — Time-based TLS Flush (std only)

The TLS batch buffer normally flushes when it reaches 32 items. Additionally, if the Daemon tick counter has advanced by at least flush_tick_threshold since the last flush, the buffer is force-drained even if nearly empty. This prevents hot items from being invisible to the Daemon for too long (the “split-brain eviction” bug).

Source

pub fn insert_t1(&self, key: K, value: V)

Insert a key-value pair directly as a high-priority “genius” item. This bypasses the L1 probation filter, doesn’t use the thread-local batch buffer, and assigns the item the maximum survival rank (e.g. 255) and promotes it to T1 immediately.

Source

pub fn remove(&self, key: &K)

Remove a key from the cache.

Source

pub fn clear(&self)

Clear all cached data.

Trait Implementations§

Source§

impl<K, V, S: Clone, Tls: TlsProvider + Clone> Clone for DualCacheFF<K, V, S, Tls>

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<K, V, S, Tls: TlsProvider> Drop for DualCacheFF<K, V, S, Tls>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<K, V, S, Tls> Freeze for DualCacheFF<K, V, S, Tls>
where S: Freeze, Tls: Freeze,

§

impl<K, V, S = RandomState, Tls = DefaultTls> !RefUnwindSafe for DualCacheFF<K, V, S, Tls>

§

impl<K, V, S, Tls> Send for DualCacheFF<K, V, S, Tls>
where S: Send, K: Send + Sync, V: Send + Sync,

§

impl<K, V, S, Tls> Sync for DualCacheFF<K, V, S, Tls>
where S: Sync, K: Send + Sync, V: Send + Sync,

§

impl<K, V, S, Tls> Unpin for DualCacheFF<K, V, S, Tls>
where S: Unpin, Tls: Unpin,

§

impl<K, V, S, Tls> UnsafeUnpin for DualCacheFF<K, V, S, Tls>
where S: UnsafeUnpin, Tls: UnsafeUnpin,

§

impl<K, V, S = RandomState, Tls = DefaultTls> !UnwindSafe for DualCacheFF<K, V, S, Tls>

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, 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.