pub struct Cache { /* private fields */ }Expand description
A connected cache, shared by every worker.
Cloning is cheap: the underlying redis::aio::ConnectionManager is
reference-counted and reconnects on its own, so a clone shares one
connection rather than opening another.
Implementations§
Source§impl Cache
impl Cache
Sourcepub async fn connect(config: &CacheConfig) -> Result<Option<Cache>, CacheError>
pub async fn connect(config: &CacheConfig) -> Result<Option<Cache>, CacheError>
Connect the cache an app’s [cache] section describes.
Ok(None) means the app configured none, which is the default and not
an error. Err means it asked for one that can’t be reached — worth
failing the boot over, because a function written against a cache and
silently given none is a bug that only shows up as a load spike.
Sourcepub async fn execute(&self, request: &str) -> Result<Value, CacheError>
pub async fn execute(&self, request: &str) -> Result<Value, CacheError>
Run one operation, given as the JSON a function sent across the ABI, and return the JSON reply.
This is the single entry point the host bridge uses, which is what keeps
the ABI to one cache call instead of one per verb — a new operation
costs a variant of Op, not a change to the contract every compiled
function was built against.
Sourcepub async fn get(&self, key: &str) -> Result<Option<Value>, CacheError>
pub async fn get(&self, key: &str) -> Result<Option<Value>, CacheError>
Read a value, or None when the key is absent or expired.
A value that isn’t valid JSON (something else wrote it) comes back as a JSON string rather than as an error — the caller asked for whatever is there.
Sourcepub async fn set(
&self,
key: &str,
value: &Value,
ttl: Option<u64>,
) -> Result<(), CacheError>
pub async fn set( &self, key: &str, value: &Value, ttl: Option<u64>, ) -> Result<(), CacheError>
Write a value. ttl of None uses [cache] default_ttl_secs; 0
means “no expiry” in both places.
Sourcepub async fn delete(&self, key: &str) -> Result<bool, CacheError>
pub async fn delete(&self, key: &str) -> Result<bool, CacheError>
Remove a key. true when it was there.
Sourcepub async fn exists(&self, key: &str) -> Result<bool, CacheError>
pub async fn exists(&self, key: &str) -> Result<bool, CacheError>
Whether a key is present and unexpired.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Cache
impl !UnwindSafe for Cache
impl Freeze for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
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