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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Write policies for controlling write operations across cache layers.
//!
//! This module defines the CompositionWritePolicy trait and its implementations.
//! Different strategies (sequential, optimistic parallel) can be used to optimize
//! write performance and availability based on application requirements.
use async_trait;
use ;
use Future;
use crateBackendError;
pub use OptimisticParallelWritePolicy;
pub use ;
pub use SequentialWritePolicy;
/// Policy trait for controlling write operations across cache layers.
///
/// This trait encapsulates the **control flow strategy** (sequential, parallel, conditional)
/// for writing to multiple cache layers, while delegating the actual write operations
/// to provided closures. This design allows the same policy to be used at both the
/// `CacheBackend` level (typed data) and `Backend` level (raw bytes).
///
/// # Type Parameters
///
/// The policy is generic over:
/// * `E` - The error type (e.g., `BackendError`)
/// * `F1, F2` - Closures for writing to L1 and L2
/// * `O` - The offload type for background task execution
///
/// # Example
///
/// ```ignore
/// use hitbox_backend::composition::policy::CompositionWritePolicy;
///
/// let policy = SequentialWritePolicy::default();
///
/// // Use with CacheBackend level
/// policy.execute_with(
/// key.clone(),
/// |k| async { l1.set::<User>(&k, value, ttl).await },
/// |k| async { l2.set::<User>(&k, value, ttl).await },
/// &offload,
/// ).await?;
/// ```