3 releases

0.1.2 Jul 27, 2024
0.1.1 Jul 26, 2024
0.1.0 Jul 26, 2024

#1064 in Database interfaces

Download history 345/week @ 2024-07-24 37/week @ 2024-07-31 33/week @ 2024-09-11 18/week @ 2024-09-18 13/week @ 2024-09-25 5/week @ 2024-10-02

69 downloads per month

Apache-2.0

17KB
372 lines

rdcache

Crates.io MIT/Apache-2 licensed

Rust version of rockscache

Features

  • Execute an async task only once for the same key at the same time and diffrent application.
  • Use MessagePack to cache data.

Example

use std::time::Duration;

use rdcache::{Client, Options};
use rustis::client::Client as RedisClient;

#[tokio::main]
async fn main() {
    let rdb = RedisClient::connect("127.0.0.1:6379").await.unwrap();
    let client = Client::new(rdb, Options::default());

    let key = "key";

    let r = client
        .fetch(key, Duration::from_secs(600), || async {
            println!("Fetching data from the database");
            Ok(Some("data".to_string()))
        })
        .await;

    println!("{:?}", r);

    client.tag_as_deleted(key).await.unwrap();

    let r = client
        .fetch(key, Duration::from_secs(600), || async {
            println!("Fetching data from the database");
            Ok(Some("data2".to_string()))
        })
        .await;

    println!("{:?}", r);
}

The output will be like:

Fetching data from the database
Ok(Some("data"))
Fetching data from the database
Ok(Some("data2"))

Dependencies

~9–18MB
~263K SLoC