cashier

Crates.iocashier
lib.rscashier
version0.1.3
sourcesrc
created_at2024-02-03 02:52:05.833637
updated_at2024-02-14 16:19:03.185582
descriptionGeneralized Data KV Cache Module
homepagehttps://github.com/myyrakle/cashier/blob/master/README.md
repositoryhttps://github.com/myyrakle/cashier
max_upload_size
id1125070
size71,683
myyrakle (myyrakle)

documentation

https://docs.rs/cashier/latest/cashier

README

cashier

GitHub license

This is a module for Key Value caching. Provides cache operation through the same interface for various data sources. Features currently provided include in-memory, redis, and AWS dynamo.

features

  • dynamo: AWS DynamoDB
  • redis: Redis

install

If you want to use only the dynamo feature, install it as follows.

[dependencies]
cashier = { version = "0.1.0", features = ["dynamo"] }

If you want to use all features, use "full".

[dependencies]
cashier = { version = "0.1.0", features = ["full"] }

Basic

use cashier::{dynamo, Cashier};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut cashier = dynamo::DynamoCashier::new()
        .table_name("cashier2")
        .config(aws_config::load_from_env().await);

    cashier.connect().unwrap();

    // If the table does not exist, it is automatically created. (Generated in on-demand mode.)
    cashier.create_table_if_not_exists().unwrap();

    // Set new data
    cashier.set("asda2sd", "value").unwrap();

    // Set a cache that expires in 10 seconds
    cashier.set_with_ttl("foo", "bar", 10).unwrap();

    // Get saved cache data.
    let foo = cashier.get("asda2sd").unwrap();
    println!("foo: {:?}", foo);

    // Reset all data.
    cashier.clear().unwrap();

    Ok(())
}

Commit count: 0

cargo fmt