Skip to main content

DualCacheFF

Struct DualCacheFF 

Source
pub struct DualCacheFF<K, V, S = RandomState> {
    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,
}

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.

Implementations§

Source§

impl<K, V> DualCacheFF<K, V, RandomState>
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> DualCacheFF<K, V, RandomState>
where K: Hash + Eq + Send + Sync + Clone + 'static, V: Send + Sync + Clone + 'static,

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, S> DualCacheFF<K, V, S>
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 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> Clone for DualCacheFF<K, V, S>

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

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.