pub enum QueryPolicy {
UpdateAlways,
UpdateBadData,
UpdateChecksumMismatch,
UpdateExpired,
ReturnAlways,
ReturnBadDataErr,
ReturnChecksumMismatch,
ReturnExpired,
}Expand description
The policy for querying the cache.
Holds various toggles for when to update the cache and when to return
stale data. This type follows a bitflag pattern, so multiple flags can
be combined using the | operator.
The default policy is QueryPolicy::default_set(), which is
equivalent to the following example.
§Examples
let q = Query::new("unique_key").policy(
QueryPolicy::UpdateBadData
| QueryPolicy::UpdateChecksumMismatch
| QueryPolicy::UpdateExpired
| QueryPolicy::ReturnExpired
);Variants§
UpdateAlways
Always update the cache when a Query::update_fn is provided.
This option overrides the other Update...flags and will always
update the cache. If not set then the cache will only be updated if
the data is bad or stale. Outlined in the below flags.
Generally this should not be set because:
- It defeats the purpose of a TTL
- Alfred can spawn many instances of a process in a short period of time, e.g. one for each character typed, this could result in many unnecessary updates (depending on what type of data you’re storing).
UpdateBadData
Update the cache if the data is bad (fails to deserialize).
Generally this should be set because if the data is bad then you want to correct it in the cache.
UpdateChecksumMismatch
Update the cache if the checksum is different.
Generally this should be set because the checksum is used to determine if the data is still applicable.
UpdateExpired
Update the cache if the data is expired.
ReturnAlways
Always return data if it is available.
This option is forward compatible with any other flags that may be
added in the future for returning data. Right now it is equivalent
to ReturnBadDataErr | ReturnChecksumMismatch | ReturnExpired.
Generally this should not be set.
ReturnBadDataErr
Return the error if the data is bad, QueryError::BadData which
contains the deserialization error in the source.
If not set then QueryError::Miss will be returned.
Whether this should be set depends on whether your code is planning on handling the error.
ReturnChecksumMismatch
Return data even if the checksum is different.
If not set then QueryError::Miss will be returned.
Generally this should not be set because the checksum is used to determine if the data is still applicable.
ReturnExpired
Return data if it is expired.
If not set then QueryError::Miss will be returned.
Generally this should be set because for Alfred workflows it is desirable to return something even if the data is expired.
Implementations§
Source§impl QueryPolicy
impl QueryPolicy
Sourcepub fn default_set() -> FlagSet<Self>
pub fn default_set() -> FlagSet<Self>
Returns the default policy.
The default enables the following flags only.
Trait Implementations§
Source§impl<R: Into<FlagSet<QueryPolicy>>> BitAnd<R> for QueryPolicy
impl<R: Into<FlagSet<QueryPolicy>>> BitAnd<R> for QueryPolicy
Source§impl<R: Into<FlagSet<QueryPolicy>>> BitOr<R> for QueryPolicy
impl<R: Into<FlagSet<QueryPolicy>>> BitOr<R> for QueryPolicy
Source§impl<R: Into<FlagSet<QueryPolicy>>> BitXor<R> for QueryPolicy
impl<R: Into<FlagSet<QueryPolicy>>> BitXor<R> for QueryPolicy
Source§impl Clone for QueryPolicy
impl Clone for QueryPolicy
Source§fn clone(&self) -> QueryPolicy
fn clone(&self) -> QueryPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more