pub struct Store { /* private fields */ }Expand description
An open redb database shared by a RedbCache and a RedbQueue.
Cloning is cheap (an Arc handle over one redb::Database), so
Self::cache / Self::queue hand out independent wrappers sharing the
same underlying database.
Store::in_memory opens an ephemeral database, so this example is fully
runnable with no filesystem access. Share one Store between a
crate::SimbadResolver (via crate::CacheBackend::custom) and a
crate::BatchResolver to have both operate over the same rows.
use simbad_resolver::Store;
let store = Store::in_memory()?;
let cache = store.cache(); // implements `Cache`
let queue = store.queue(); // implements `Queue`Implementations§
Source§impl Store
impl Store
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, CacheError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, CacheError>
Open (creating if missing) a durable, file-backed store at path,
with the default BatchDurability::Durable bulk-load policy —
exactly today’s behavior. See Store::open_with to opt into
BatchDurability::Eventual batch loads.
§Errors
Returns CacheError::Backend if the database cannot be opened or its
tables cannot be initialised.
use simbad_resolver::Store;
let path = std::env::temp_dir().join("simbad-resolver-doctest-store-open.redb");
let store = Store::open(&path)?; // creates the file if missing
assert!(path.exists());Sourcepub fn open_with(
path: impl AsRef<Path>,
bulk_durability: BatchDurability,
) -> Result<Self, CacheError>
pub fn open_with( path: impl AsRef<Path>, bulk_durability: BatchDurability, ) -> Result<Self, CacheError>
Like Store::open, but configuring the BatchDurability every
Cache::upsert_batch call against this store uses.
§Errors
Returns CacheError::Backend if the database cannot be opened or its
tables cannot be initialised.
Sourcepub fn in_memory() -> Result<Self, CacheError>
pub fn in_memory() -> Result<Self, CacheError>
Open a fresh, ephemeral in-memory store (nothing persisted to disk),
with the default BatchDurability::Durable bulk-load policy.
BatchDurability::Eventual only matters for a file-backed store
(there’s no “reopen after a crash” scenario for an in-memory one), so
unlike Store::open this has no _with variant; add one if that
changes.
§Errors
Returns CacheError::Backend if the in-memory database cannot be
created or its tables cannot be initialised.
Sourcepub fn cache(&self) -> RedbCache
pub fn cache(&self) -> RedbCache
A RedbCache over this store’s database, inheriting its configured
BatchDurability.