jayesbe / react-native-cacheable-image

An Image Component for React Native that will cache itself to disk.
MIT License
304 stars 78 forks source link

How to clean up all the cache image #32

Open luojinghui opened 7 years ago

luojinghui commented 7 years ago

in code, How to clean up all the cache image?

abelaska commented 7 years ago

That's a good point. Function to remove all cached images would be very useful.

jayesbe commented 7 years ago

Agreed. There should be a mechanism to remove the cached file. I think a static function for removing all cached images would work. Something like CacheableImage.clearCache();

For individual components I am thinking a property like 'clearCacheOnDestroy' as a boolean. Once set, on componentWillUnmount() it should check to see if the prop is set and if so remove it from the cache.

Thoughts ?

luojinghui commented 7 years ago

So, now only manually to delete the cache, and can not function to delete these pictures?

wachunei commented 7 years ago

I was looking at the source code and it actually has a method that deletes the cached file (_deleteFilePath, here it is in use).

This method argument is filePath, which is calculated here at line 52, and uses cachePath and cacheKeys as variables.

Both variables are assigned in _processSource method.

So what would I do in order to delete a specific image from the cache:

@jayesbe What do you think? If is there something I'm missing let me know.

If this is fine for you I'd happily create a PR with this.

jayesbe commented 7 years ago

@wachunei This makes sense to me. PR is definitely welcome.

wachunei commented 7 years ago

@jayesbe will look into this next days!