Skip to main content

dualcache_ff/componant/
config.rs

1//! Static Configuration Policy for DualCacheCore
2//! Uses a Trait-based Static Config pattern for maximum extensibility and zero runtime overhead.
3
4pub trait CachePolicy {
5    type Evict: crate::componant::policy::EvictionPolicy + Default;
6    
7    /// Hit count threshold to promote from Local TLS Cache to T2 Core Cache.
8    const T2_THRESHOLD: u16;
9    /// Hit count threshold to promote from T2 to T1.
10    const T1_THRESHOLD: u16;
11    /// Hit count threshold to promote from T1 to T0.
12    const T0_THRESHOLD: u16;
13
14    /// Compile-Time Assertions
15    /// Forces the user-defined thresholds to be powers of two.
16    const _ASSERT_POWER_OF_TWO: () = {
17        assert!(Self::T2_THRESHOLD.is_power_of_two(), "T2 Threshold must be 2^n");
18        assert!(Self::T1_THRESHOLD.is_power_of_two(), "T1 Threshold must be 2^n");
19        assert!(Self::T0_THRESHOLD.is_power_of_two(), "T0 Threshold must be 2^n");
20    };
21}
22
23/// The default Exponential Policy scaling latency thresholds by 2^n.
24pub struct DefaultExponentialPolicy;
25
26impl CachePolicy for DefaultExponentialPolicy {
27    type Evict = crate::componant::policy::DefaultEvictionPolicy;
28    
29    const T2_THRESHOLD: u16 = 2;   // Local to T2 (T2 threshold not strictly defined in earlier prompts but 2 fits 2^1)
30    const T1_THRESHOLD: u16 = 16;  // T2 to T1
31    const T0_THRESHOLD: u16 = 256; // T1 to T0
32}