Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Size #36

Open
Waterbyte opened this issue Jan 6, 2017 · 4 comments
Open

Cache Size #36

Waterbyte opened this issue Jan 6, 2017 · 4 comments

Comments

@Waterbyte
Copy link

How to set up Cache Size? I'm working on a project which could have thousands of image so obviously i just want library to cache only the latest image and dynamically remove the older one with a fixed cache size. Is there any way, I could implement it?

@jayesbe
Copy link
Owner

jayesbe commented Jan 30, 2017

If you create a CacheableImage component

<CacheableImage source={{uri: someUrl }} > </CacheableImage>

Then when you change the source on the same component, it will delete the original cached image, and replace it with the updated source. The component understands it's state.

If you don't replace the CacheableImage source but instead create a new CacheableImage with the new source, a new image will be cached. The original Image will also be held in cache.

if you load the app and restore the state from the last time the app closed, it would start the application with the last cached image. Then you can update the source on the CacheableImage and it will first remove the original image from the cache and replace it with the new source.

@wachunei
Copy link

wachunei commented Jan 30, 2017

I'm developing an app which uses a lot of images, our idea is to have them cached along with our state cache we're building, in #32 I mentioned a way to clear cache of specific images, I'd definitely use that in our project, but I want to be sure: If I forget to delete my cached images or something goes wrong whilst our cleaning method is running and some pictures don't get deleted: is there a way to setup a cache cleaning? will my cached pictures stay there forever?

@jayesbe
Copy link
Owner

jayesbe commented Jan 30, 2017

We can probably create an additional static method ClearAll() or something that will iterate over the directory that contains the cached files and remove them all. Maybe we can make the function smarter and pass a white-list of files to be kept and remove the others... thoughts?

@wachunei
Copy link

Sounds good to me. I think it could be smarter in these ways:

  • Whenever the directory hits a certain size, delete older cached images
  • Whenever the cached image has been there for X amount of time, delete it.

Both solutions would require to save the date of caching somewhere, which is a solution of other caching components (e.g. setting up a database, which I don't believe necessary to have).

Since the cache clearing would be bounded to our models/state cache clearing, deleting cached images per source url and the whole folder would be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants