#cache #async #concurrent

shared-expiry-get

Simple concurrent async get with expiration for Rust

3 releases (breaking)

0.2.0 Jan 26, 2021
0.1.0 Jan 8, 2020
0.0.1 May 5, 2019

#431 in Concurrency

Download history 39/week @ 2022-10-07 6/week @ 2022-10-14 35/week @ 2022-10-21 93/week @ 2022-10-28 48/week @ 2022-11-04 37/week @ 2022-11-11 28/week @ 2022-11-18 13/week @ 2022-11-25 35/week @ 2022-12-02 45/week @ 2022-12-09 15/week @ 2022-12-16 27/week @ 2022-12-23 7/week @ 2022-12-30 23/week @ 2023-01-06 7/week @ 2023-01-13 30/week @ 2023-01-20

82 downloads per month

MIT license

21KB
466 lines

Simple concurrent async get with expiration for Rust.

Latest Version Docs

shared-expiry-get is a wrapper for accessing and caching a remote data source with some expiration criteria.

Features

  • retrieve only once even if multiple threads are trying to access the remote data at the same time
  • async support
  • update data on expiration

shared-expiry-get does not:

  • retry on error

Example Use Cases

  • cached access of an http source respecting cache control
  • cached access of a file which may get updated

A basic Example

#[derive(Clone)]
struct MyProvider {}
#[derive(Clone)]
struct Payload {}

impl Expiry for Payload {
    fn valid(&self) -> bool {
        true
    }
}

impl Provider<Payload> for MyProvider {
    fn update(&self) -> ExpiryFut<Payload> {
        future::ok::<Payload, ExpiryGetError>(Payload {}).into_future().boxed()
    }
}

async fn main() {
    let rs = RemoteStore::new(MyProvider {});
    let payload = rs.get().await;
    assert!(payload.is_ok());
}

Dependencies

~1–1.5MB
~32K SLoC