cachemap 0.1.0

A concurrent insert-only hashmap for caching values
Documentation
  • Coverage
  • 87.5%
    7 out of 8 items documented2 out of 7 items with examples
  • Size
  • Source code size: 8.33 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.75 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hclarke

CacheMap

CacheMap is a data structure for concurrently caching values.

the cache function will look up a value in the map, or generate and store a new one using the provided function

Example

use cachemap::CacheMap;
	
let m = CacheMap::new();

let fst = m.cache("key", || 5u32).as_ref();
let snd = m.cache("key", || 7u32).as_ref();

assert_eq!(*fst, *snd);
assert_eq!(*fst, 5u32);

Features 🌞

  • can cache values concurrently (using &CacheMap<K,V> rather than &mut CacheMap<K,V>)
  • returned references use the map's lifetime, so clients can avoid smart pointers
  • clients can optionally get Arc<V> pointers, in case values need to outlive the map
  • values can be addes as Arc<V>, allowing unsized values, and re-using Arc<V>s from elsewhere

MisFeatures 💧

A cache with a bad policy is another name for a memory leak

this map provides only one way to remove things from the cache: drop the entire map.