1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2025-2026 Adrian Robinson. Licensed under the AGPL-3.0.
// See LICENSE file in the project root for full license text.
//! Eviction policies for tiered cache management.
//!
//! This module contains eviction logic for both L1 (in-memory) and L2 (Redis)
//! caches, using a consistent tan-curve scoring algorithm.
//!
//! # Architecture
//!
//! ```text
//! ┌──────────────────────────────────────────────────────────────┐
//! │ Eviction Module │
//! ├──────────────────────────────────────────────────────────────┤
//! │ tan_curve.rs - Core scoring algorithm │
//! │ └─ TanCurveMemoryPressure: pressure → multiplier │
//! │ └─ TanCurvePolicy: recency + frequency + size → score │
//! │ └─ CacheEntry: generic entry metadata for scoring │
//! ├──────────────────────────────────────────────────────────────┤
//! │ redis.rs - Redis-specific eviction │
//! │ └─ RedisEvictionManager: proactive eviction before LRU │
//! │ └─ RedisMemoryProfile: cached INFO MEMORY to avoid RTT │
//! │ └─ Protected prefixes: merkle:*, idx:* │
//! └──────────────────────────────────────────────────────────────┘
//! ```
//!
//! # L1 Memory Eviction
//!
//! L1 eviction is handled directly in `coordinator/mod.rs` using `TanCurvePolicy`.
//! The coordinator builds `CacheEntry` from `SyncItem` and calls `select_victims()`.
//!
//! # L2 Redis Eviction
//!
//! Redis eviction is proactive - we evict before Redis LRU kicks in to protect
//! infrastructure keys (merkle trees, RediSearch indexes). The `RedisEvictionManager`
//! tracks key metadata and uses `TanCurvePolicy` for consistent scoring.