pub struct CacheRepository { /* private fields */ }Expand description
Cache repository using PostgreSQL UNLOGGED table with per-query TTL check
Implementations§
Source§impl CacheRepository
impl CacheRepository
pub fn new(pool: PgPool) -> Self
Sourcepub async fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
pub async fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
Get a cached value, returning None if not found or expired
Sourcepub async fn set<T: Serialize>(
&self,
key: &str,
value: &T,
ttl_secs: u64,
) -> Result<()>
pub async fn set<T: Serialize>( &self, key: &str, value: &T, ttl_secs: u64, ) -> Result<()>
Set a cached value with TTL in seconds
Sourcepub async fn set_with_expiry<T: Serialize>(
&self,
key: &str,
value: &T,
expires_at: DateTime<Utc>,
) -> Result<()>
pub async fn set_with_expiry<T: Serialize>( &self, key: &str, value: &T, expires_at: DateTime<Utc>, ) -> Result<()>
Set a cached value with explicit expiration time
Sourcepub async fn cleanup_expired(&self) -> Result<u64>
pub async fn cleanup_expired(&self) -> Result<u64>
Delete all expired entries (cleanup)
Sourcepub async fn get_or_set<T, F, Fut>(
&self,
key: &str,
ttl_secs: u64,
fetch: F,
) -> Result<T>
pub async fn get_or_set<T, F, Fut>( &self, key: &str, ttl_secs: u64, fetch: F, ) -> Result<T>
Get or set a cached value using a fallback function
Trait Implementations§
Source§impl Clone for CacheRepository
impl Clone for CacheRepository
Source§fn clone(&self) -> CacheRepository
fn clone(&self) -> CacheRepository
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CacheRepository
impl !RefUnwindSafe for CacheRepository
impl Send for CacheRepository
impl Sync for CacheRepository
impl Unpin for CacheRepository
impl UnsafeUnpin for CacheRepository
impl !UnwindSafe for CacheRepository
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
Mutably borrows from an owned value. Read more
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>
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 more