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