Coder Social home page Coder Social logo

Comments (10)

wkh237 avatar wkh237 commented on August 16, 2024

Hi @jbrodriguez , it would be great to have such mechanism to reduce network traffic, but I'm wondering if it is sufficient to make such decision merely base on the URL. Perhaps it would be better to implement something that uses cache control headers ? This might already included in AsyncHttpClient, but I'm not sure if it works as I thought. If you would give a hand at this issue it would be grateful.

from react-native-fetch-blob.

jbrodriguez avatar jbrodriguez commented on August 16, 2024

@wkh237 right, cache control headers sounds great, the only downside is that you need to have control of the server: if you don't, then it's possible that you won't receive the headers.

An alternative could be to use a 'key' property, pretty much the same as what React does with every component. It 'key' is not present, the fallback would be the url.

I'll take a look at both ideas.

from react-native-fetch-blob.

wkh237 avatar wkh237 commented on August 16, 2024

I suppose the cache mechanism should be optional, because the response data of the same URL won't be the same in many cases.

from react-native-fetch-blob.

jbrodriguez avatar jbrodriguez commented on August 16, 2024

That gives me an idea ...

If there's a cache entry in the config object, md5 that string to create the filename for the blob and check for its presence before attempting to download.

It there's no cache entry, work as it currently does.

What do you think ?

from react-native-fetch-blob.

wkh237 avatar wkh237 commented on August 16, 2024

Do you mean that there will be something like this ?

let fetch = RNFetchBlob.config({
    cache : 'user avatar'
})
fetch('GET', AVATAR_URL,).then(...)

Well it's fine, but I prefer to make it simply a boolean let developers decide if they're going to use the cache mechanism, just like what browsers do :D

from react-native-fetch-blob.

jbrodriguez avatar jbrodriguez commented on August 16, 2024

What you mean is for the caching to be transparent to the developer (just set a flag and forget it) ?

But in the end you need some key (be the cache entry, be the url or any other idea) to check if the resource has changed or not.

This is how cache busting works in browsers.

For instance https://www.quora.com/How-does-browser-caching-works.

Caching generally works on url and to you can 'bust' the cache by changing the url (appending a non-op string such as '?v2')

But I'm guessing you have a different use case.

Let me know what you think.

from react-native-fetch-blob.

wkh237 avatar wkh237 commented on August 16, 2024

Hi @jbrodriguez , just in case someone may already using it in their application, changing default behavior may cause unpredictable problem, so I'd like to make this mechanism optional at this moment.

By the way, I think use key property is a good idea. It also inspired me that perhaps we can design some components which can be used this way

<POST.onPress key="sign up" url="http://example.com/signup/" body={this.state.credential}>
    <Text>Sign Up</Text>
</POST.onPress>

from react-native-fetch-blob.

jbrodriguez avatar jbrodriguez commented on August 16, 2024

Hi @wkh237,

Ok, let me see if I follow.

Your suggestion would be something like:

const key = 'avatar-' + this.state.userName
// or const key = 'sign up',  like you mentioned

let fetch = RNFetchBlob.config({
    ....
    cache: true,
    key
})

fetch('GET', AVATAR_URL,).then(...)

If developer decides no cache, then

const key = 'avatar-' + this.state.userName

let fetch = RNFetchBlob.config({
    ....
    cache: false,
})

fetch('GET', AVATAR_URL,).then(...)

or

const key = 'avatar-' + this.state.userName

let fetch = RNFetchBlob.config({
    ....
})

fetch('GET', AVATAR_URL,).then(...)

// in the latter case, cache is ommitted which is equivalent to cache: false

Is that how you're visualizing it ?

from react-native-fetch-blob.

wkh237 avatar wkh237 commented on August 16, 2024

@jbrodriguez , Thank you for your patient, I think a key property is enough : )

use cache

const key = 'avatar-' + this.state.userName
// or const key = 'sign up',  like you mentioned

let fetch = RNFetchBlob.config({
    ....
    key
})

fetch('GET', AVATAR_URL,).then(...)

not to use cache, work as it currently does

const key = 'avatar-' + this.state.userName

let fetch = RNFetchBlob.config({
    ....
})

fetch('GET', AVATAR_URL,).then(...)

How do you think ?

from react-native-fetch-blob.

jbrodriguez avatar jbrodriguez commented on August 16, 2024

@wkh237, yes that looks great.

I'll take a look at this asap.

from react-native-fetch-blob.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.