Struct merino_cache::MemoryCacheSuggester
source · [−]pub struct MemoryCacheSuggester {
inner: Box<dyn SuggestionProvider>,
metrics_client: StatsdClient,
items: Arc<DedupedMap<String, Instant, Vec<Suggestion>>>,
default_ttl: Duration,
default_lock_timeout: Duration,
max_background_removals: usize,
}
Expand description
A in-memory cache for suggestions.
Fields
inner: Box<dyn SuggestionProvider>
The suggester to query on cache-miss.
metrics_client: StatsdClient
The Statsd client used to record statistics.
items: Arc<DedupedMap<String, Instant, Vec<Suggestion>>>
The cached items.
default_ttl: Duration
TTL to apply to items if the underlying provider does not give one.
default_lock_timeout: Duration
TTL for locks on cache refresh updates
max_background_removals: usize
Maximum number of entries to remove in a single background expiration iteration.
Implementations
sourceimpl Suggester
impl Suggester
sourcepub fn new_boxed(
config: MemoryCacheConfig,
provider: Box<dyn SuggestionProvider>,
metrics_client: StatsdClient
) -> Box<Self>
pub fn new_boxed(
config: MemoryCacheConfig,
provider: Box<dyn SuggestionProvider>,
metrics_client: StatsdClient
) -> Box<Self>
Create a in-memory suggestion cache from settings that wraps provider
.
sourcefn remove_expired_entries(&mut self)
fn remove_expired_entries(&mut self)
Remove expired entries from items
sourcefn clone_with_null_provider(&self) -> Self
fn clone_with_null_provider(&self) -> Self
It is often useful to have access to most of the fields on this object,
but providers are not generally cloneable, so self.inner
cannot be
cloned.
Introducing an Arc around inner
complicates things, but the situations
where we want clones of this object don’t need the inner provider. So
perform a partial clone that clones most fields, replacing the provider
with a dummy value.
Trait Implementations
sourceimpl SuggestionProvider for Suggester
impl SuggestionProvider for Suggester
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,
query: 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,
query: 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 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 provider, using a new configuration object. State should be preserved if possible. Read more
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