pub struct QueryClient { /* private fields */ }
Expand description
The query client for sycamore-query
. This stores your default settings,
the cache and all queries that need to be updated when a query is refetched
or updated. The client needs to be provided as a Context object in your top
level component (sycamore
) or index view (perseus
).
§Example
#[component]
pub fn App<G: Html>(cx: Scope) -> View<G> {
let client = QueryClient::new(ClientOptions::default());
provide_context(cx, client);
// You can now use the sycamore-query hooks
view! { cx, }
}
Implementations§
Source§impl QueryClient
impl QueryClient
Sourcepub fn new(default_options: ClientOptions) -> Rc<Self>
pub fn new(default_options: ClientOptions) -> Rc<Self>
Sourcepub fn invalidate_queries(self: Rc<Self>, queries: Vec<Vec<u64>>)
pub fn invalidate_queries(self: Rc<Self>, queries: Vec<Vec<u64>>)
Invalidate all queries whose keys start with any of the keys passed in.
For example, passing a top level query ID will invalidate all queries
with that top level ID, regardless of their arguments.
For passing multiple keys with tuple types, see keys!
.
§Example
// This will invalidate all queries whose keys start with `"hello"`,
// or where the first key is `"user"` and the first argument `3`
client.invalidate_queries(keys!["hello", ("user", 3)]);
Sourcepub fn collect_garbage(&self)
pub fn collect_garbage(&self)
Collect garbage from the client cache Call this whenever a lot of queries have been removed (i.e. on going to a different page) to keep memory usage low. Alternatively you could call this on a timer with the same length as your cache expiration time.
This will iterate through the entire cache sequentially, so don’t use on every frame.
Sourcepub fn query_data<K: AsKeys, T: 'static>(&self, key: K) -> Option<Rc<T>>
pub fn query_data<K: AsKeys, T: 'static>(&self, key: K) -> Option<Rc<T>>
Fetch query data from the cache if it exists. If it doesn’t or the data
is expired, this will return None
.
Sourcepub fn set_query_data<K: AsKeys, T: 'static>(&self, key: K, value: T)
pub fn set_query_data<K: AsKeys, T: 'static>(&self, key: K, value: T)
Override the query data in the cache for a given key. This will update all queries with the same key automatically to reflect the new data.