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
//! Cache hit/miss accounting.
/// A point-in-time snapshot of a [`CachedIndex`](crate::CachedIndex)'s cache.
///
/// Returned by [`CachedIndex::cache_stats`](crate::CachedIndex::cache_stats).
/// `hits` and `misses` are monotonic counters over the cache's lifetime;
/// `len` and `capacity` describe its current occupancy. Use
/// [`hit_rate`](CacheStats::hit_rate) to turn the counters into a ratio for
/// tuning.
///
/// # Examples
///
/// ```
/// use iqdb_cache::CacheStats;
///
/// let stats = CacheStats {
/// hits: 75,
/// misses: 25,
/// evictions: 8,
/// len: 64,
/// capacity: 128,
/// };
/// assert_eq!(stats.lookups(), 100);
/// assert!((stats.hit_rate() - 0.75).abs() < f64::EPSILON);
/// ```