pub struct Cache { /* private fields */ }Expand description
Cache wrapper for Redis operations
Implementations§
Source§impl Cache
impl Cache
Sourcepub async fn get<T>(&self, key: &str) -> Result<Option<T>>where
T: for<'de> Deserialize<'de>,
pub async fn get<T>(&self, key: &str) -> Result<Option<T>>where
T: for<'de> Deserialize<'de>,
Get a cached value as JSON
Sourcepub async fn set<T>(&self, key: &str, value: &T, ttl: u64) -> Result<()>where
T: Serialize,
pub async fn set<T>(&self, key: &str, value: &T, ttl: u64) -> Result<()>where
T: Serialize,
Set a cached value as JSON
Sourcepub async fn delete_pattern(&self, pattern: &str) -> Result<()>
pub async fn delete_pattern(&self, pattern: &str) -> Result<()>
Delete multiple keys matching a glob pattern using Redis SCAN
Sourcepub async fn invalidate_org(&self, org_id: &Uuid) -> Result<()>
pub async fn invalidate_org(&self, org_id: &Uuid) -> Result<()>
Invalidate organization-related caches
Sourcepub async fn invalidate_user(&self, user_id: &Uuid) -> Result<()>
pub async fn invalidate_user(&self, user_id: &Uuid) -> Result<()>
Invalidate user-related caches
Sourcepub async fn invalidate_subscription(&self, org_id: &Uuid) -> Result<()>
pub async fn invalidate_subscription(&self, org_id: &Uuid) -> Result<()>
Invalidate subscription cache
Sourcepub async fn invalidate_marketplace(
&self,
content_type: &str,
content_id: &Uuid,
) -> Result<()>
pub async fn invalidate_marketplace( &self, content_type: &str, content_id: &Uuid, ) -> Result<()>
Invalidate marketplace content cache
Sourcepub async fn get_or_set<F, Fut, T>(
&self,
key: &str,
ttl: u64,
f: F,
) -> Result<T>where
F: FnOnce() -> Fut,
Fut: Future<Output = Result<T>>,
T: Serialize + for<'de> Deserialize<'de>,
pub async fn get_or_set<F, Fut, T>(
&self,
key: &str,
ttl: u64,
f: F,
) -> Result<T>where
F: FnOnce() -> Fut,
Fut: Future<Output = Result<T>>,
T: Serialize + for<'de> Deserialize<'de>,
Get or set pattern: Try cache first, fallback to database query
Auto Trait Implementations§
impl Freeze for Cache
impl !RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
impl !UnwindSafe for Cache
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.