Debian Codegraph @

third_party/rust/cachemap2/README.md

raw
1 # CacheMap
2
3 CacheMap is a data structure for concurrently caching values.
4
5 The `cache` function will look up a value in the map, or generate and store a new one using the
6 provided function.
7
8 This is a updated and maintained fork of [hclarke/cachemap](https://github.com/hclarke/cachemap).
9
10 ## Example
11
12 ```
13 use cachemap::CacheMap;
14
15 let m = CacheMap::new();
16
17 let fst = m.cache("key", || 5u32);
18 let snd = m.cache("key", || 7u32);
19
20 assert_eq!(*fst, *snd);
21 assert_eq!(*fst, 5u32);
22 ```
23
24 ## Features
25
26 - Can cache values concurrently (using `&CacheMap<K,V>` rather than `&mut CacheMap<K,V>`).
27 - Returned references use the map's lifetime, so clients can avoid smart pointers.
28 - Clients can optionally enable the `dashmap` feature, which uses `dashmap` internally and allows:
29 - getting `Arc<V>` pointers, in case values need to outlive the map, and
30 - adding `Arc<V>` directly, allowing unsized values, and re-using `Arc<V>`s from elsewhere.
31 - Clients can optionally enable the `abi_stable` feature which will derive `abi_stable::StableAbi`
32 on the type.
33
34 ## AntiFeatures
35
36 - There is no cache invalidation: the only way to remove things from a CacheMap is to drop it.