Skip to content

React Native and Cache #363

Open
Open
@magnuskrona

Description

@magnuskrona

Hi!

Describe the bug

I have a question about React Native and cache. I have set the cacheLife option to enable the cache. Even if the value is set, there is always a network request made.
But, if I enable debugging in the app with for example React Native Debugger and enable Network Inspect, the cache mechanism seems to work like it should. The data is cached for the amount of time set in the options. But as soon as I disable the debugger, nothing is cached again.

I'm using a Provider to set the url and the options:
<Provider url={API_URL} options={options}> {children} </Provider>

Setting up with useFetch:
const { get, post, response, loading, error } = useFetch(API_URL);

Calling get:
const myData = await get('/api/mydata?filter=' + filter);

Expected behavior
Setting the cacheLife option > 0 should cache the data in React Native

Any idea why this could be happening? I have tried on both simulator and device and it's the same problem on both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions