actix_diesel_cache
A library with actor which provides caching for small and rarely changing tables in databases.
Add to Cargo.toml
:
toml
actix_diesel_cache = "0.1.0"
```rust use diesel::prelude::*;
table! { shop (id) { id -> Int4, name -> Text, address -> Text, } }
struct Shop { id: i32, name: String, address: String, }
impl actixdieselcache::Cache
async fn example(conn: SqliteConnection) -> actixdieselcache::Result<()> { let addr = actixdieselcache::CacheDbActor::new(conn)?.start();
let shop = Shop {
id: 1,
name: "Adidas",
address: "Central street",
};
addr.send(actix_diesel_cache::Save(shop)).await.unwrap()?;
let shop1 = addr.send(actix_diesel_cache::Get(shop.id)).await.unwrap()?;;
assert_eq!(shop, shop1);
let shops = addr.send(actix_diesel_cache::GetAll::default()).await.unwrap()?;;
assert_eq!(shops, vec![shop]);
} ```