GithubHelp home page GithubHelp logo

Comments (5)

sladkoff avatar sladkoff commented on June 4, 2024 3

Also here's how I batched my image requests in case anyone needs this:

import {ImageCacheProvider} from 'react-native-cached-image';
import {Promise as Bluebird} from 'bluebird';

function downloadImages(imageUrls) { 
    var chunks = [];
    var chunkSize = 10;
    // split large array of image urls into chunks
    for (var i = 0, j = imageUrls.length; i < j; i += chunkSize) {
        chunks.push(imageUrls.slice(i, i + chunkSize));
     }

    // I used the Bluebird Promise library to wait for each batch of requests to finish before starting another
    return Bluebird.each(chunks, (chunk) => {
        return ImageCacheProvider.cacheMultipleImages(chunk);
    })
}

from react-native-cached-image.

kfiroo avatar kfiroo commented on June 4, 2024

Hey @sladkoff
Currently we start a prefetch task for each url concurrently and let the underlying native code handle the workload, I think what's happening is that you are overloading it with requests and it runs out of memory.

You could implement you own ImageCacheProvider to handle this, or you could try calling cacheMultipleImages with smaller batches

from react-native-cached-image.

kfiroo avatar kfiroo commented on June 4, 2024

Also, we are saving all images to RNFetchBlob.fs.dirs.CacheDir see docs
I'm not sure if this space is limited.

from react-native-cached-image.

sladkoff avatar sladkoff commented on June 4, 2024

Hey @kfiroo
Thanks for the quick answer.
I'm now batching the requests and it works perfectly.

I read up on the Android cache dir.
It doesn't seem to have limited space but it's still not recommended to store critical data since it may be purged automatically when the device storage runs full.

You should always maintain the cache files yourself and stay within a reasonable limit of space consumed, such as 1MB. When the user uninstalls your application, these files are removed.

Do you think it would be possible to support different storage options in the core project in the future?
For example the component could have an optional prop which defaults to the cache dir. The ImageCacheProvider would also need a customizable option parameter.

I don't really want to maintain a copy of the project and think that the functionality has its uses...

In the meantime I'll try to implement this locally. If it works and you agree, I could open a PR.

What do you think?

from react-native-cached-image.

naytun avatar naytun commented on June 4, 2024

Try this one!! It works with expo@v25 and Iā€™m using it in my project.

https://hackernoon.com/smart-images-in-react-native-db0ef047dd8c

from react-native-cached-image.

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.