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
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Incremental build cache (manifest §7, §32).
//!
//! The dependency graph (`DepNode`) and content-addressed cache live
//! here. The MVP 5 implementation will persist to `.mos-cache/`.
use HashMap;
use ContentHash;
/// A cache entry's address. Real keys include node, style, and width
/// hashes (manifest §32). For now the type is opaque.
///
/// # Examples
///
/// ```
/// use mos_cache::CacheKey;
/// use mos_core::ContentHash;
///
/// let key = CacheKey(ContentHash(42));
///
/// assert_eq!(key.0, ContentHash(42));
/// ```
;
/// Cache trait. Implementations: in-memory (default), on-disk (MVP 5).
///
/// # Examples
///
/// ```
/// use mos_cache::{Cache, CacheKey, InMemoryCache};
/// use mos_core::ContentHash;
///
/// let mut cache = InMemoryCache::default();
/// let key = CacheKey(ContentHash(7));
/// cache.put(key, vec![1, 2, 3]);
///
/// assert_eq!(cache.get(&key), Some(vec![1, 2, 3]));
/// ```
/// Hash-map backed cache used by tests and the current MVP pipeline.
///
/// # Examples
///
/// ```
/// use mos_cache::{Cache, CacheKey, InMemoryCache};
/// use mos_core::ContentHash;
///
/// let mut cache = InMemoryCache::default();
/// let key = CacheKey(ContentHash(5));
/// cache.put(key, b"pdf".to_vec());
///
/// assert_eq!(cache.get(&key), Some(b"pdf".to_vec()));
/// ```