DylanVann / react-native-fast-image

🚩 FastImage, performant React Native image component.
MIT License
8.17k stars 1.5k forks source link

Feature Request: Allow for customization of the cache mechanism. #880

Open Jorghi12 opened 2 years ago

Jorghi12 commented 2 years ago

Describe the bug FastImage's caching approach compares whole url addresses, whereas I'd need more fine-grained control here.

To Reproduce Due to differences in the url params that correspond to various auth keys, you can have identical images with distinct urls on most image hosting platforms, leading to a cache miss in FastImage.

[Example of cache miss] https://unsplash.it/thisIsMyImage.jpg?key=1324y2389472398423 https://unsplash.it/thisIsMyImage.jpg?key=asdbfjhfsd89812812102

Expected behavior FastImage should allow you to define the cache's equality check, ideally via a prop argument.

function cacheHash(imageAddress) {
     return imageAddress.slice(0, imageAddress.find("?"))
}

<FastImage
        style={{ width: 200, height: 200 }}
        source={{
            uri: 'https://unsplash.it/thisIsMyImage.jpg?key=1324y2389472398423',
            headers: { Authorization: 'someAuthToken' },
            priority: FastImage.priority.normal,
        }}
        cacheHash={cacheHash}
        resizeMode={FastImage.resizeMode.contain}
    />

Dependency versions

Jorghi12 commented 2 years ago

If the primary maintainers want, I'd be happy to implement this feature.

Aryk commented 2 years ago

This would be a great add-on.. @Jorghi12 did you make any progress on this?

hanxiaofeng commented 1 year ago

did you make any progress on this?