Custom Resource cache lifetime
By default the NetworkManager specifies the lifetime of data and errors in the cache. If some resources are longer living, or shorter living than other, the can specify their own expiry length values, which will be passed on to all fetch shape creator functions of Resource.
Examples
Long cache lifetime
LongLivingResource.ts
// We can now extend LongLivingResource to get a resource that will be cached for one hour
abstract class LongLivingResource extends Resource {
static getFetchOptions() {
return {
...super.getFetchOptions(),
dataExpiryLength: 60 * 60 * 1000, // one hour
};
}
}
Never retry on error
NoRetryResource.ts
// We can now extend NoRetryResource to get a resource that will never retry on network error
abstract class NoRetryResource extends Resource {
static getFetchOptions() {
return {
...super.getFetchOptions(),
errorExpiryLength: Infinity,
};
}
}