I want to cache images using the react-native-fast-image library. Image URLs will not be changed over time. But the images can be changed. So the Image change will not change the image on the app. Images are stored in S3. For a solution what I thought was to keep a last image updated timestamp on the Firebase side. So when I’m updating the images I can change the timestamp and place it at the end of the image URLs.
So the image URLs will look like this
http://localhost/chair.jpg?${last_updated_timestamp}
http://localhost/chair.jpg?${last_updated_timestamp}
I’m thinking of saving the last_updated_timestamp
in Async Storage, So I can sync the timestamp from Firebase to Async Storage and use it directly for the images.
Is there any other better way I can achieve the same result?
5
Answers
This library provides a different types of caching control.
react-native-fast-image
In your cache url will not change so you can use simple caching for that component as below
you can try like this key=${this.state.source.uri}${new Date()}
Do u know frequency of updating your imag it can be used.
Set MAX-AGE of caching on image this value can be how often that image can be updated even if you will not changed it this image will be pulled again after MAX-AGE so be sure of what value be used
S3 has cache too. Our production project use S3. We have same problems with cache. And we use query params.
Its simply and effective solution if you have to solve problem at frontend.
Other solution will be related to configure not only react-native-fast-image but S3 too. Our devops didnt think that its his problem and we use query params)))
it has also happened to me a couple of months ago. I have image URL like this
https://myown.server/images/1122.png
. Image on the server was change but it does not change on the application. I have find a simple solution for this as this.Hope this will solve your problem .