pub struct RedbManager { /* private fields */ }manager-redb only.Expand description
Implements CacheManager with redb
as the backend — a pure-Rust, embedded, persistent key/value store.
All operations are synchronous and require no async runtime, so this
manager works under any executor (tokio, smol, Bevy, …) and adds no
tokio dependency.
Implementations§
Source§impl RedbManager
impl RedbManager
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
Creates a new RedbManager, creating or opening the redb database
file at path.
Returns an error if the database cannot be opened (for example if another instance already holds the exclusive file lock).
Sourcepub fn from_database(db: Arc<Database>) -> Result<Self>
pub fn from_database(db: Arc<Database>) -> Result<Self>
Wraps an already-open redb Database, allowing callers to configure
the database (cache size, etc.) before handing it to the manager.
Sourcepub fn from_database_with_flush_interval(
db: Arc<Database>,
flush_interval: u64,
) -> Result<Self>
pub fn from_database_with_flush_interval( db: Arc<Database>, flush_interval: u64, ) -> Result<Self>
Like from_database, but flushes stores to
disk every flush_interval writes instead of the default 64. An
interval of 1 flushes after every store.
Sourcepub fn from_database_with_max_bytes(
db: Arc<Database>,
flush_interval: u64,
max_bytes: u64,
) -> Result<Self>
pub fn from_database_with_max_bytes( db: Arc<Database>, flush_interval: u64, max_bytes: u64, ) -> Result<Self>
Wraps an already-open redb Database, flushing every
flush_interval writes and keeping the stored entries within
max_bytes. When a store takes the cache over the limit, the entries
written longest ago are removed in the same transaction. A response
that is larger than max_bytes on its own is not cached, and is
removed if it is already in the database.
The limit counts the serialized entries, not the database file, which is larger and does not shrink right away when entries are removed. Entries already in the database count towards the limit. Do not open one database with and without a limit at the same time, or let a version of this crate without size limits write to it in between: entries stored that way are not counted or removed until the manager is opened again.