#expire #time #map #live #entries #configured #expiring

expiring_map

A map whose entries expire after a configured time to live

1 unstable release

Uses old Rust 2015

0.1.0 Nov 24, 2018

#308 in Caching

Download history 2/week @ 2024-07-26 1/week @ 2024-08-02 6/week @ 2024-08-09 26/week @ 2024-08-16 11/week @ 2024-08-23 11/week @ 2024-08-30 20/week @ 2024-09-06 3/week @ 2024-09-13 25/week @ 2024-09-20 19/week @ 2024-09-27 17/week @ 2024-10-04 9/week @ 2024-10-11 11/week @ 2024-10-18 13/week @ 2024-10-25 17/week @ 2024-11-01

51 downloads per month
Used in 2 crates

MIT/Apache

8KB
140 lines

Expiring Map

The expiring map is a wrapper around a hash map, where each entry expires some time after being inserted. The intended use is for caching in places where you want to ensure the data does not become stale.

Usage

use expiring_map::ExpiringMap;
use std::time::Duration;

let time_to_live = Duration::from_secs(60);
let mut map = ExpiringMap::new(time_to_live);

map.insert("keyA".to_owned(), "valA".to_owned());

assert_eq!(Some(&"valA".to_owned()), map.get("keyA"));

// after 60 seconds has passed since "keyA" was inserted
// map.remove_expired_entries();

Even if map entries have expired, they are not removed from the map until remove_expired_entries is called.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps