Crates.io | cashier |
lib.rs | cashier |
version | 0.1.3 |
source | src |
created_at | 2024-02-03 02:52:05.833637 |
updated_at | 2024-02-14 16:19:03.185582 |
description | Generalized Data KV Cache Module |
homepage | https://github.com/myyrakle/cashier/blob/master/README.md |
repository | https://github.com/myyrakle/cashier |
max_upload_size | |
id | 1125070 |
size | 71,683 |
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.
dynamo
: AWS DynamoDBredis
: RedisIf 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"] }
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(())
}