QueryPolicy

Enum QueryPolicy 

Source
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§

Trait Implementations§

Source§

impl<R: Into<FlagSet<QueryPolicy>>> BitAnd<R> for QueryPolicy

Source§

type Output = FlagSet<QueryPolicy>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: R) -> Self::Output

Performs the & operation. Read more
Source§

impl<R: Into<FlagSet<QueryPolicy>>> BitOr<R> for QueryPolicy

Source§

type Output = FlagSet<QueryPolicy>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: R) -> Self::Output

Performs the | operation. Read more
Source§

impl<R: Into<FlagSet<QueryPolicy>>> BitXor<R> for QueryPolicy

Source§

type Output = FlagSet<QueryPolicy>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: R) -> Self::Output

Performs the ^ operation. Read more
Source§

impl Clone for QueryPolicy

Source§

fn clone(&self) -> QueryPolicy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueryPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<QueryPolicy> for FlagSet<QueryPolicy>

Source§

fn from(value: QueryPolicy) -> Self

Converts to this type from the input type.
Source§

impl Not for QueryPolicy

Source§

type Output = FlagSet<QueryPolicy>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl PartialEq for QueryPolicy

Source§

fn eq(&self, other: &QueryPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<R: Into<FlagSet<QueryPolicy>>> Rem<R> for QueryPolicy

Source§

type Output = FlagSet<QueryPolicy>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: R) -> Self::Output

Performs the % operation. Read more
Source§

impl<R: Into<FlagSet<QueryPolicy>>> Sub<R> for QueryPolicy

Source§

type Output = FlagSet<QueryPolicy>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: R) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for QueryPolicy

Source§

impl Eq for QueryPolicy

Source§

impl StructuralPartialEq for QueryPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.