Struct merino_cache::RedisCacheSuggester
source · [−]pub struct RedisCacheSuggester {
inner: Box<dyn SuggestionProvider>,
redis_connection: ConnectionManager,
metrics_client: StatsdClient,
default_ttl: Duration,
default_lock_timeout: Duration,
}
Expand description
A suggester that uses Redis to cache previous results.
Fields
inner: Box<dyn SuggestionProvider>
The suggester to query on cache-miss.
redis_connection: ConnectionManager
Connection to Redis.
metrics_client: StatsdClient
The Statsd client used to record statistics.
default_ttl: Duration
The default amount of time a cache entry is valid, unless overridden by
inner
.
default_lock_timeout: Duration
Default lock timeout
Implementations
sourceimpl Suggester
impl Suggester
sourcepub fn new_boxed<'__async_fut>(
settings: Settings,
config: RedisCacheConfig,
metrics_client: StatsdClient,
provider: Box<dyn SuggestionProvider + 'static>
) -> impl '__async_fut + Future<Output = Result<Box<Self>, SetupError>> where
Settings: '__async_fut,
RedisCacheConfig: '__async_fut,
StatsdClient: '__async_fut,
Box<dyn SuggestionProvider + 'static>: '__async_fut,
pub fn new_boxed<'__async_fut>(
settings: Settings,
config: RedisCacheConfig,
metrics_client: StatsdClient,
provider: Box<dyn SuggestionProvider + 'static>
) -> impl '__async_fut + Future<Output = Result<Box<Self>, SetupError>> where
Settings: '__async_fut,
RedisCacheConfig: '__async_fut,
StatsdClient: '__async_fut,
Box<dyn SuggestionProvider + 'static>: '__async_fut,
Create a Redis suggestion provider from settings that wraps provider
.
Opens a connection to Redis.
Errors
Fails if it cannot connect to Redis.
sourceasync fn get_key(&self, key: &str) -> Result<CacheCheckResult, SuggestError>
async fn get_key(&self, key: &str) -> Result<CacheCheckResult, SuggestError>
Retrieve an item from the cache
If the item retrieved cannot be deserialized, it will be deleted. If there is no TTL for the retrieved item, one will be added to it.
sourcefn queue_store_key(
&self,
key: &str,
suggestions: Vec<Suggestion>,
lock: String
) -> Result<(), SuggestError>
fn queue_store_key(
&self,
key: &str,
suggestions: Vec<Suggestion>,
lock: String
) -> Result<(), SuggestError>
Queue a command to store an entry in the cache.
This runs as a separate task, and this function returns before the operation is complete.
Errors
Returns an error if the command cannot be queued. Does not error if the command fails to run to completion.
sourcefn queue_delete_key(&self, key: &str) -> Result<(), SuggestError>
fn queue_delete_key(&self, key: &str) -> Result<(), SuggestError>
Queue a command to delete a key from the cache.
This runs as a separate task, and this function returns before the deletion is complete.
Errors
Returns an error if the command cannot be queued. Does not error if the command fails to run to completion.
sourcefn queue_set_key_ttl(
&self,
key: &str,
ttl: Duration
) -> Result<(), SuggestError>
fn queue_set_key_ttl(
&self,
key: &str,
ttl: Duration
) -> Result<(), SuggestError>
Queue a command to set the TTL of a key in the cache.
This runs as a separate task, and this function returns before the operation is complete.
Errors
Returns an error if the command cannot be queued. Does not error if the command fails to run to completion.
Trait Implementations
sourceimpl SuggestionProvider for Suggester
impl SuggestionProvider for Suggester
sourcefn reconfigure<'life0, 'life1, 'async_trait>(
&'life0 mut self,
new_config: Value,
make_fresh: &'life1 MakeFreshType
) -> Pin<Box<dyn Future<Output = Result<(), SetupError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn reconfigure<'life0, 'life1, 'async_trait>(
&'life0 mut self,
new_config: Value,
make_fresh: &'life1 MakeFreshType
) -> Pin<Box<dyn Future<Output = Result<(), SetupError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Reconfigure the Redis provider.
Note that the reconfiguration will not wipe out the Redis cache.
It only reconfigures the inner provider and other cache settings such
as default_ttl
for the subsequent cache operations.
sourcefn cache_inputs(
&self,
req: &SuggestionRequest,
cache_inputs: &mut dyn CacheInputs
)
fn cache_inputs(
&self,
req: &SuggestionRequest,
cache_inputs: &mut dyn CacheInputs
)
Generate a set of cache inputs for a given query specific to this provider. Any property of the query that affects how suggestions are generated should be included. Read more
sourcefn suggest<'life0, 'async_trait>(
&'life0 self,
request: SuggestionRequest
) -> Pin<Box<dyn Future<Output = Result<SuggestionResponse, SuggestError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn suggest<'life0, 'async_trait>(
&'life0 self,
request: SuggestionRequest
) -> Pin<Box<dyn Future<Output = Result<SuggestionResponse, SuggestError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Provide suggested results for query
.
sourcefn is_null(&self) -> bool
fn is_null(&self) -> bool
Return if this provider is null and can be ignored. Providers that set this to true should be ignored in any place where suggestions are needed. Providers with this set to true likely only serve as a blank space where we may need a provider but can’t otherwise supply one. Read more
sourcefn cache_key(&self, req: &SuggestionRequest) -> String
fn cache_key(&self, req: &SuggestionRequest) -> String
Use Self::cache_inputs
to generate a single cache key. This function
should not normally be overridden by provider implementations. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Suggester
impl Send for Suggester
impl Sync for Suggester
impl Unpin for Suggester
impl !UnwindSafe for Suggester
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> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
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
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