website/versioned_docs/version-v20.1.0/guided-tour/reusing-cached-data/fetch-policies.md
import DocsRating from '@site/src/core/DocsRating'; import {OssOnly, FbInternalOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
The first step to reusing locally cached data is to pass a fetchPolicy to the loadQuery function, which can be provided by useQueryLoader (see the Fetching Queries section):
const React = require('React');
const {graphql} = require('react-relay');
function AppTabs() {
const [
queryRef,
loadQuery,
] = useQueryLoader(HomeTabQuery);
const onSelectHomeTab = () => {
loadQuery({id: '4'}, {fetchPolicy: 'store-or-network'});
}
// ...
}
The provided fetchPolicy will determine:
By default, Relay will try to read the query from the local cache; if any piece of data for that query is missing or stale, it will fetch the entire query from the network. This default fetchPolicy is called "store-or-network".
Specifically, fetchPolicy can be any of the following options: **
Note that the refetch function discussed in the Fetching and Rendering Different Data section also takes a fetchPolicy.