Comments (10)
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.
@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.
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.
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.
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.
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.
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.
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.
@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.
@wkh237, yes that looks great.
I'll take a look at this asap.
from react-native-fetch-blob.
Related Issues (20)
- Error calling RCTDeviceEventEmitter.emit failed to create value from json HOT 3
- react-native-fetch-blob has memory leak during update download progress
- Multiple dex files define Lcom/RNFetchBlob/RNFetchBlobConst; HOT 2
- Could not store file in a specified path HOT 1
- New format of IOS 11 files (HEIF and HEVC) are giving error when uploading
- Invalid value for visibility : 2 HOT 3
- Native module BlobModule is required for blob support HOT 1
- react-native-fetch-blob image upload failed for android(always receives zero bytes)
- Save file to internal storage HOT 4
- Execution failed for task ':react-native-fetch-blob:verifyReleaseResources'. HOT 3
- Does anybody have good example for base64 encoding and decoding for video and image?
- Build is failing due to jcenter dependency disappearing HOT 4
- Cannot download run background in iOS
- Cannot fetch jpeg image multipart/form-data.
- RNFetchBlob blocked firebase/firestore call react native HOT 1
- iOS build failed xcode 10
- android.actionViewIntent not working
- skip some bytes of file in Multipart form-data
- joltup/rn-fetch-blob is absolute SHIT
- RNFetchBlob.fetchBlobForm failed to create request body - Issue happens intermediately HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-fetch-blob.