Struct cached::RedisCache
source · [−]pub struct RedisCache<K, V> { /* private fields */ }
Expand description
Cache store backed by redis
Values have a ttl applied and enforced by redis. Uses an r2d2 connection pool under the hood.
Implementations
sourceimpl<K, V> RedisCache<K, V> where
K: Display,
V: Serialize + DeserializeOwned,
impl<K, V> RedisCache<K, V> where
K: Display,
V: Serialize + DeserializeOwned,
sourcepub fn new<S: AsRef<str>>(prefix: S, seconds: u64) -> RedisCacheBuilder<K, V>
pub fn new<S: AsRef<str>>(prefix: S, seconds: u64) -> RedisCacheBuilder<K, V>
Initialize a RedisCacheBuilder
sourcepub fn connection_string(&self) -> String
pub fn connection_string(&self) -> String
Return the redis connection string used
Trait Implementations
sourceimpl<'de, K, V> IOCached<K, V> for RedisCache<K, V> where
K: Display,
V: Serialize + DeserializeOwned,
impl<'de, K, V> IOCached<K, V> for RedisCache<K, V> where
K: Display,
V: Serialize + DeserializeOwned,
type Error = RedisCacheError
sourcefn cache_get(&self, key: &K) -> Result<Option<V>, RedisCacheError>
fn cache_get(&self, key: &K) -> Result<Option<V>, RedisCacheError>
Attempt to retrieve a cached value
sourcefn cache_set(&self, key: K, val: V) -> Result<Option<V>, RedisCacheError>
fn cache_set(&self, key: K, val: V) -> Result<Option<V>, RedisCacheError>
Insert a key, value pair and return the previous value
sourcefn cache_remove(&self, key: &K) -> Result<Option<V>, RedisCacheError>
fn cache_remove(&self, key: &K) -> Result<Option<V>, RedisCacheError>
Remove a cached value
sourcefn cache_lifespan(&self) -> Option<u64>
fn cache_lifespan(&self) -> Option<u64>
Return the lifespan of cached values (time to eviction)
sourcefn cache_set_lifespan(&mut self, seconds: u64) -> Option<u64>
fn cache_set_lifespan(&mut self, seconds: u64) -> Option<u64>
Set the lifespan of cached values, returns the old value
sourcefn cache_set_refresh(&mut self, refresh: bool) -> bool
fn cache_set_refresh(&mut self, refresh: bool) -> bool
Set the flag to control whether cache hits refresh the ttl of cached values, returns the old flag value
Auto Trait Implementations
impl<K, V> !RefUnwindSafe for RedisCache<K, V>
impl<K, V> Send for RedisCache<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for RedisCache<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for RedisCache<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> !UnwindSafe for RedisCache<K, V>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more