shared-expiry-get

Crates.ioshared-expiry-get
lib.rsshared-expiry-get
version0.2.0
sourcesrc
created_at2019-05-05 18:56:19.800277
updated_at2021-01-26 10:32:42.791314
descriptionSimple concurrent async get with expiration for Rust
homepage
repositoryhttps://github.com/fiji-flo/shared-expiry-get
max_upload_size
id132266
size57,545
Florian Dieminger (fiji-flo)

documentation

https://docs.rs/crate/shared-expiry-get

README

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());
}
Commit count: 20

cargo fmt