pub struct Store { /* private fields */ }Expand description
The cache database, shared by the threads of one process.
Implementations§
Source§impl Store
impl Store
Sourcepub fn open(cache_dir: &Path) -> Result<Self, StoreError>
pub fn open(cache_dir: &Path) -> Result<Self, StoreError>
Opens the database in the db directory of cache_dir, creating it, with the
current schema version and the current CacheIdentity, if it does not exist.
An existing database’s schema version is checked first, then its identity.
§Errors
StoreError::SchemaMismatch when the database has another schema version,
StoreError::IdentityMismatch when it has another identity,
StoreError::IdentityMissing when it has this schema version but no
identity, and another StoreError when the database cannot be created or
opened.
Sourcepub fn inventory(cache_dir: &Path) -> Result<Inventory, StoreError>
pub fn inventory(cache_dir: &Path) -> Result<Inventory, StoreError>
Counts the entries of the database in the db directory of cache_dir,
whatever its schema version, by their keys alone, and reads its schema version
and its identity when it can, without decoding another record or changing
anything. A cache without a database has no entries.
§Errors
A StoreError when the database cannot be opened or read.
Sourcepub fn wipe(cache_dir: &Path) -> Result<(), StoreError>
pub fn wipe(cache_dir: &Path) -> Result<(), StoreError>
Wipes the whole cache database in the db directory of cache_dir, whatever
its schema version and identity; the next Store::open creates an empty one,
stamped with the current identity. The caller holds the cache lock, so no
process has the database open.
The directory is first renamed, in one step, so a crash during the removal leaves no partial database behind, only a directory that the next wipe removes.
§Errors
StoreError::Wipe when the directory cannot be renamed or removed.
Sourcepub fn read(&self) -> Result<Txn<'_>, StoreError>
pub fn read(&self) -> Result<Txn<'_>, StoreError>
Sourcepub fn write(&self) -> Result<Txn<'_>, StoreError>
pub fn write(&self) -> Result<Txn<'_>, StoreError>
Begins a read-write transaction, which changes nothing until it is committed.
§Errors
StoreError::Database when the database cannot begin one.
Sourcepub fn close(self) -> Result<(), StoreError>
pub fn close(self) -> Result<(), StoreError>
Closes the database, after every commit that has started.
§Errors
StoreError::Database when closing fails.