Struct QueryClient

Source
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

Source

pub fn new(default_options: ClientOptions) -> Rc<Self>

Creates a new QueryClient.

§Arguments
  • default_options - The global query options.
§Example
let client = QueryClient::new(ClientOptions::default());
Source

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)]);
Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for QueryClient

Source§

fn default() -> QueryClient

Returns the “default value” for a type. Read more

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> 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, 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.