5 releases

0.1.3 Feb 14, 2024
0.1.2 Feb 14, 2024
0.1.1 Feb 14, 2024
0.1.0 Feb 14, 2024
0.0.0 Feb 3, 2024

#1226 in Database interfaces

MIT license

22KB
459 lines

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(())
}

Dependencies

~3–17MB
~199K SLoC