Core Cache Persistence
gqless
offers easy to use Cache persistence
.
client.backupPersistence
gets all the cache and returns a string, and optionally accepts aversion
string parameter, that allows for invalidating previous versions of cache, and ignoring them.client.restorePersistence
accepts a possible string that should have been stored persistently in some way, and optionally accepts a secondversion
string paramater, that should be the same as the one used inbackupPersistence
.
#
Data RevalidationFor an effective usage of Cache persistence
it's almost always required some kind of automatic data refetching,
and for that reason we recommend you to use:
React
- useQuery and graphql HOC
staleWhileRevalidate
, - useTransactionQuery and useLazyQuery
cache-and-network
fetchPolicy,
And setting them by default in your defaults.
- useQuery and graphql HOC
Core
- resolved's onCacheData function.
#
ExamplesIn both examples we use a debounce
function exported from gqless
that reduces the amount calls to the storages, improving the user experience.
Here you can read a quick explanation of debouncing
#
localStorageIn this example, for simplicity we are using localStorage
to offer cache persistence,
but for most serious applications we recommend using async solutions like localForage.
#
Async StoragesWe recommend using localForage or @react-native-async-storage/async-storage