kfiroo / react-native-cached-image

CachedImage component for react-native
MIT License
938 stars 470 forks source link

Cache path component from host #95

Closed chrusart closed 6 years ago

chrusart commented 6 years ago

File path in cache is created using getCachePath which removes non alphanumerical signs from host, and generateCacheKey which creates SHA1 from path (without host). If we will have the same file path (not so often, but...) on different hosts, the same file path will be created and previous one overwritten i guess. It can happen that the same file will be returned for different urls. I don't know what was the reason to remove non alphanumerical signs from host (i can guess), but this method (getCachePath) should be changed.

For example: mysi.te/photo.jpg my.site/photo.jpg or: 11.11.11.11/photo.jpg 1.111.1.11/photo.jpg will produce the same cache key (every photo.jpg has a different content).

kfiroo commented 6 years ago

@chrusart Thanks, I see what you are saying. How likely would you say that would happen? Also, any idea how to change the logic to make it more robust?

chrusart commented 6 years ago

Very rare. Probably you want to have human readable host part and have cache files separated from different hosts, then I would add some host hash to it at the end like: mysite_eie2uouo5eu42dioeu4/3oe2d16b4ae6u2ioe6ud5b.jpg

chrusart commented 6 years ago

If you agree than I can make quick PR.

kfiroo commented 6 years ago

@chrusart Yeah, sure, This is a great idea! Thanks! :)