pub struct QueryOptions {
pub key: QueryKey,
pub cache_policy: CachePolicy,
pub request_policy: RequestPolicy,
pub retry_policy: RetryPolicy,
pub gc_time_ms: u64,
pub keep_previous_data: bool,
pub force_fetch: bool,
pub refetch_on_mount: RefetchTrigger,
pub refetch_on_window_focus: RefetchTrigger,
pub refetch_on_reconnect: RefetchTrigger,
}hook only.Expand description
Options for use_query and fetch_query.
§Quick Start
use gpui_query::QueryOptions;
use gpui_query::core::{CachePolicy, RetryPolicy};
use gpui_query::hook::use_query;
// Simplest: just a string key
let result = use_query("users", |signal| async move {
Ok::<Vec<User>, MyError>(vec![])
}, cx);
// With options:
let result = use_query(
QueryOptions::new("users")
.cache_policy(CachePolicy::Ttl { ttl_ms: 300_000 })
.retry_policy(RetryPolicy::new(5)),
|signal| async move {
Ok::<Vec<User>, MyError>(vec![])
},
cx,
);Fields§
§key: QueryKeyThe query key. Can be a string or multi-segment key.
cache_policy: CachePolicyCache policy. Default: Ttl { ttl_ms: 60_000 }.
request_policy: RequestPolicyRequest policy. Default: LatestWins.
retry_policy: RetryPolicyRetry policy. Default: 3 retries with exponential backoff.
gc_time_ms: u64GC time in milliseconds. Default: 300_000 (5 minutes).
Reserved / forward-compat (audit fix #80): settable via the
.gc_time(ms) builder, but not yet consumed by use_query,
fetch_query, or the bucket layer. Garbage collection currently runs
off the global GC time set via [QueryClient::with_gc_time]; this
per-query value is stored only so a future release can honor it without
a breaking API change. Setting it has no effect today.
keep_previous_data: boolWhether to keep previous data when the key changes.
Reserved / forward-compat (audit fix #80): settable via the
.keep_previous() builder, but not yet consumed by use_query or
use_query_manual. The placeholderData/keepPreviousData behavior is
not yet implemented; the field is stored so a future release can honor
it without a breaking API change. Setting it has no effect today.
force_fetch: boolWhether to force a fetch (ignore cache).
When true, use_query passes QueryFetchMode::Force to
begin_request, bypassing cache freshness checks and always starting
a new fetch.
refetch_on_mount: RefetchTriggerRefetch on mount trigger.
Reserved / forward-compat (audit fix #80): settable on the struct, but not yet consumed. The GPUI event-system integration for automatic refetching on component mount is not yet implemented; the field is stored so a future release can honor it without a breaking API change. Setting it has no effect today.
refetch_on_window_focus: RefetchTriggerRefetch on window focus trigger.
Reserved / forward-compat (audit fix #80): settable on the struct, but not yet consumed. The GPUI event-system integration for automatic refetching on window focus is not yet implemented; the field is stored so a future release can honor it without a breaking API change. Setting it has no effect today.
refetch_on_reconnect: RefetchTriggerRefetch on reconnect trigger.
Reserved / forward-compat (audit fix #80): settable on the struct, but not yet consumed. The GPUI event-system integration for automatic refetching on reconnect is not yet implemented; the field is stored so a future release can honor it without a breaking API change. Setting it has no effect today.
Implementations§
Source§impl QueryOptions
impl QueryOptions
Sourcepub fn force(self) -> Self
pub fn force(self) -> Self
Force a fetch, ignoring cache.
When set, use_query passes QueryFetchMode::Force to begin_request,
which bypasses cache freshness checks and always starts a new fetch.
Sourcepub fn keep_previous(self) -> Self
pub fn keep_previous(self) -> Self
Keep previous data when the key changes.
Reserved / forward-compat (audit fix #80): sets the
keep_previous_data field, which is not yet consumed by use_query
or use_query_manual. The keepPreviousData behavior is intended for a
future release (preserve the prior data/previous_data slot across a
key change so the component keeps rendering the last successful result
while the new fetch is in flight). The builder is provided now so callers
can opt in without a future API change; calling it has no effect today.
Source§impl QueryOptions
impl QueryOptions
Sourcepub fn cache_policy(self, policy: CachePolicy) -> Self
pub fn cache_policy(self, policy: CachePolicy) -> Self
Set the cache policy.
Sourcepub fn request_policy(self, policy: RequestPolicy) -> Self
pub fn request_policy(self, policy: RequestPolicy) -> Self
Set the request policy.
Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Set the retry policy.
Trait Implementations§
Source§impl Clone for QueryOptions
impl Clone for QueryOptions
Source§fn clone(&self) -> QueryOptions
fn clone(&self) -> QueryOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QueryOptions
impl Debug for QueryOptions
Source§impl Default for QueryOptions
impl Default for QueryOptions
Source§impl From<&str> for QueryOptions
impl From<&str> for QueryOptions
Source§impl From<(QueryKey, CachePolicy, RequestPolicy)> for QueryOptions
Build QueryOptions from a raw (key, cache_policy, request_policy)
triple.
impl From<(QueryKey, CachePolicy, RequestPolicy)> for QueryOptions
Build QueryOptions from a raw (key, cache_policy, request_policy)
triple.
Audit fix #79: this lets use_query_manual_opts /
use_query_unsignalled_opts accept callers that already hold the legacy
raw-parameter triple without forcing them to spell out QueryOptions::new.
Non-breaking: the existing constructors and From impls are untouched.
Source§fn from(
(key, cache_policy, request_policy): (QueryKey, CachePolicy, RequestPolicy),
) -> Self
fn from( (key, cache_policy, request_policy): (QueryKey, CachePolicy, RequestPolicy), ) -> Self
Source§impl From<QueryKey> for QueryOptions
impl From<QueryKey> for QueryOptions
Auto Trait Implementations§
impl Freeze for QueryOptions
impl RefUnwindSafe for QueryOptions
impl Send for QueryOptions
impl Sync for QueryOptions
impl Unpin for QueryOptions
impl UnsafeUnpin for QueryOptions
impl UnwindSafe for QueryOptions
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().