pub struct CacheConfig { /* private fields */ }Available on crate feature
cache-aio only.Expand description
Configuration for client side caching.
Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates new CacheConfig with default values (10_000 LRU size and 30 minutes of client ttl)
Sourcepub fn set_mode(self, mode: CacheMode) -> Self
pub fn set_mode(self, mode: CacheMode) -> Self
Sets how client side caching should work, default is CacheMode::All.
Sourcepub fn set_size(self, size: NonZeroUsize) -> Self
pub fn set_size(self, size: NonZeroUsize) -> Self
Sets maximum key count for the cache.
Sourcepub fn set_default_client_ttl(self, ttl: Duration) -> Self
pub fn set_default_client_ttl(self, ttl: Duration) -> Self
Sets the default client side time to live (TTL) for cached values, this value will be used when a TTL isn’t explicitly passed with crate::Cmd::set_cache_config/crate::Pipeline::set_cache_config.
Client side caching mechanism will compare client side TTL with server side TTL and pick minimum to retain in the cache.
Client side TTL is the maximum time for a key to stay in cache.
Server side TTL is the maximum time for a key to stay in server, it’s requested using PTTL command for each key.
§Examples
let client = redis::Client::open("redis://127.0.0.1/?protocol=resp3").unwrap();
// Set default client side time to live as 60 seconds instead of 30 minutes default.
let cache_config = CacheConfig::new().set_default_client_ttl(Duration::from_secs(60));
let async_config = AsyncConnectionConfig::new().set_cache_config(cache_config);
let mut connection = client.get_multiplexed_async_connection_with_config(&async_config).await.unwrap();
// Command below will use client side time to live of 60 seconds from cache configuration.
let key_1: Option<String> = redis::cmd("GET").arg("KEY_1").query_async(&mut connection).await.unwrap();
// Command below will have client side time to live of 5 seconds;
let command_cache_config = CommandCacheConfig::new().set_client_side_ttl(Duration::from_secs(5));
let key_2: Option<String> = redis::cmd("GET").arg("KEY_2").set_cache_config(command_cache_config).query_async(&mut connection).await.unwrap();Trait Implementations§
Source§impl Clone for CacheConfig
impl Clone for CacheConfig
Source§fn clone(&self) -> CacheConfig
fn clone(&self) -> CacheConfig
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 moreSource§impl Debug for CacheConfig
impl Debug for CacheConfig
Source§impl Default for CacheConfig
impl Default for CacheConfig
impl Copy for CacheConfig
Auto Trait Implementations§
impl Freeze for CacheConfig
impl RefUnwindSafe for CacheConfig
impl Send for CacheConfig
impl Sync for CacheConfig
impl Unpin for CacheConfig
impl UnwindSafe for CacheConfig
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