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
89
90
91
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//! The core trait for cache storage backends.
//!
//! [`CacheTier`] defines the interface that all cache backends must implement.
//! This trait is designed for composition: implement the storage operations,
//! then use `cachet` to layer on telemetry, TTL, and multi-tier fallback.
use Future;
use crate::;
/// Trait for cache tier implementations.
///
/// Implement this trait to create custom cache backends. The cache system
/// wraps these in `CacheWrapper` to add telemetry and TTL support.
///
/// # Consistency
///
/// Implementations must provide **read-after-write monotonicity** on a single
/// instance: once `insert(key, entry)` returns `Ok(())`, any subsequent call to
/// `get(key)` on the same instance must never return data older than what was
/// written. It may return `None` (e.g., if the entry was evicted or invalidated)
/// or a newer value, but never a stale one that predates the most recent write.
///
/// This guarantee is scoped to a **single instance** - if the same backing store
/// is accessed through multiple `CacheTier` instances (e.g., separate processes
/// connected to the same Redis cluster), replication lag or network partitions
/// may cause one instance to observe stale data written through another. The
/// monotonicity guarantee only applies to reads and writes through the same
/// Rust object.
///
/// `len` and `is_empty` have default implementations:
/// - `len`: Returns `Err(SizeError::unsupported())` (not all tiers track size)
/// - `is_empty`: Delegates to [`len`](Self::len), returning `Ok(true)` when
/// the reported length is `0` and otherwise propagating any `SizeError`