Note The main branch includes many breaking changes, switch to v0.3 branch for the released version.
Basteh(previously actix-storage) is a type erased wrapper around some key-value storages to provide common operations.
Basteh is meant to be used alongside one the implementer crates, ex:
# Cargo.toml
[dependencies]
basteh = "=0.4.0-alpha.5"
basteh-memory = "=0.4.0-alpha.5"
After you picked a backend:
use basteh::{Basteh, BastehError};
use basteh_memory::MemoryBackend;
async fn handler() -> Result<String, BastehError> {
// Intialize the implementer according to its docs
let provider = MemoryBackend::start_default();
// Give it to the Storage struct
let basteh = Basteh::build().provider(provider).finish();
// Set a key, value can be stringy, bytes or numbers
basteh.set("key", "value").await;
// And make it expire after 5 seconds
basteh.expire("key", Duration::from_secs(5)).await;
// Or just do both in one command(usually faster)
basteh.set_expiring("key", "value", Duration::from_secs(5)).await;
basteh.get::<String>("key").await
}
There is also an implementation based on sled, but because of sled's situation, it has not been released to crates.io
The word basteh
is persian for box/package, that simple! Does it sound like some other words in english? sure! But I'm bad at naming packages and my other option was testorage
as in type-erased storage... so... basteh
is cool.
The main idea for having a kv storage around while developing applications, came from my love for django framework and how it makes your life easier. There is a cache framework in django that does just that! Basteh is a bit more, it is not just for a cache but also for persistent values which is why there will always be some persistent implementations around.
Although it is designed to work with small, mostly temporary data, I don't have any plans to make it less effecient for other workflows, and pull requests are always welcome.
It can be usefull when:
- You don't know which key-value database you'll need later.
- You can't afford the long time compilation of some dbs while developing.
- memory store compiles pretty fast
- You're writing an extension library and need to support multiple storage backends.
There are bunch of examples in the examples
folder, very basic ones thought, but it will give you the idea.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.