pub struct Engram { /* private fields */ }Expand description
A reusable asynchronous cache with Moka memory and SQLite persistence tiers.
Engram is cheap to clone; clones share memory, persistence, and synchronization.
Implementations§
Source§impl Engram
impl Engram
Sourcepub fn builder() -> EngramBuilder
pub fn builder() -> EngramBuilder
Starts configuration of an Engram cache.
Sourcepub async fn get<T>(&self, key: impl AsRef<str>) -> Result<Option<T>>
pub async fn get<T>(&self, key: impl AsRef<str>) -> Result<Option<T>>
Retrieves a value, checking Moka before SQLite.
Sourcepub async fn get_key<T>(&self, key: &CacheKey<T>) -> Result<Option<T>>
pub async fn get_key<T>(&self, key: &CacheKey<T>) -> Result<Option<T>>
Retrieves a value using a caller-controlled schema tag.
Sourcepub async fn get_with_metadata<T>(
&self,
key: impl AsRef<str>,
) -> Result<Option<CacheEntry<T>>>
pub async fn get_with_metadata<T>( &self, key: impl AsRef<str>, ) -> Result<Option<CacheEntry<T>>>
Retrieves a value with expiration/source metadata.
Sourcepub async fn get_key_with_metadata<T>(
&self,
key: &CacheKey<T>,
) -> Result<Option<CacheEntry<T>>>
pub async fn get_key_with_metadata<T>( &self, key: &CacheKey<T>, ) -> Result<Option<CacheEntry<T>>>
Retrieves a value and metadata using a caller-controlled schema tag.
Sourcepub async fn get_arc<T>(&self, key: impl AsRef<str>) -> Result<Option<Arc<T>>>
pub async fn get_arc<T>(&self, key: impl AsRef<str>) -> Result<Option<Arc<T>>>
Retrieves a shared L1 value without cloning it. This is useful for large values.
Sourcepub async fn get_arc_key<T>(&self, key: &CacheKey<T>) -> Result<Option<Arc<T>>>
pub async fn get_arc_key<T>(&self, key: &CacheKey<T>) -> Result<Option<Arc<T>>>
Retrieves a shared value using a caller-controlled schema tag.
Sourcepub async fn metadata(
&self,
key: impl AsRef<str>,
) -> Result<Option<CacheMetadata>>
pub async fn metadata( &self, key: impl AsRef<str>, ) -> Result<Option<CacheMetadata>>
Returns expiry and source information without deserializing an L2 value.
Sourcepub async fn set<T>(
&self,
key: impl AsRef<str>,
value: &T,
ttl: Option<Duration>,
) -> Result<()>
pub async fn set<T>( &self, key: impl AsRef<str>, value: &T, ttl: Option<Duration>, ) -> Result<()>
Stores a value in both tiers using serialized byte length as its L1 weight.
Sourcepub async fn set_arc<T>(
&self,
key: impl AsRef<str>,
value: Arc<T>,
ttl: Option<Duration>,
) -> Result<()>
pub async fn set_arc<T>( &self, key: impl AsRef<str>, value: Arc<T>, ttl: Option<Duration>, ) -> Result<()>
Stores a shared value without cloning it for L1.
Sourcepub async fn set_key<T>(
&self,
key: &CacheKey<T>,
value: &T,
ttl: Option<Duration>,
) -> Result<()>
pub async fn set_key<T>( &self, key: &CacheKey<T>, value: &T, ttl: Option<Duration>, ) -> Result<()>
Stores a value with a caller-controlled schema tag.
Sourcepub async fn set_arc_key<T>(
&self,
key: &CacheKey<T>,
value: Arc<T>,
ttl: Option<Duration>,
) -> Result<()>
pub async fn set_arc_key<T>( &self, key: &CacheKey<T>, value: Arc<T>, ttl: Option<Duration>, ) -> Result<()>
Stores a shared value with a caller-controlled schema tag.
Sourcepub async fn set_with_weight<T>(
&self,
key: impl AsRef<str>,
value: &T,
ttl: Option<Duration>,
weight: u32,
) -> Result<()>
pub async fn set_with_weight<T>( &self, key: impl AsRef<str>, value: &T, ttl: Option<Duration>, weight: u32, ) -> Result<()>
Stores a value with an explicit L1 weight, useful when serialized size is not representative of its in-memory footprint.
Sourcepub async fn set_arc_with_weight<T>(
&self,
key: impl AsRef<str>,
value: Arc<T>,
ttl: Option<Duration>,
weight: u32,
) -> Result<()>
pub async fn set_arc_with_weight<T>( &self, key: impl AsRef<str>, value: Arc<T>, ttl: Option<Duration>, weight: u32, ) -> Result<()>
Stores an Arc with an explicit L1 weight.
Sourcepub async fn set_many<T, I, K>(
&self,
values: I,
ttl: Option<Duration>,
) -> Result<()>
pub async fn set_many<T, I, K>( &self, values: I, ttl: Option<Duration>, ) -> Result<()>
Persists many values in one SQLite transaction.
Sourcepub async fn remove(&self, key: impl AsRef<str>) -> Result<()>
pub async fn remove(&self, key: impl AsRef<str>) -> Result<()>
Removes a key from both memory and persistent storage.
Sourcepub async fn purge_expired(&self) -> Result<u64>
pub async fn purge_expired(&self) -> Result<u64>
Deletes expired SQLite rows and returns the number removed.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Engram
impl !UnwindSafe for Engram
impl Forget for Engram
impl Freeze for Engram
impl Send for Engram
impl Sync for Engram
impl Unpin for Engram
impl UnsafeUnpin for Engram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more