chrisben / imgcache.js

JS library based on the File API to cache images for offline recovery (target: cordova/phonegap & chrome)
Other
826 stars 216 forks source link

Multiple caches #231

Closed oliversalzburg closed 6 years ago

oliversalzburg commented 6 years ago

From what I saw in the source, it does not seem possible to maintain several discrete caches. Did anyone ever experiment with this?

I have several different use cases for downloaded images in our application. Some are expected to be publically available and fall into several categories, others are private.

An example of what I have in mind can be seen in instant messaging applications like WhatsApp. They will maintain a folder with images and one with animated GIFs (and several other folders). These images are available from the image/photo library of the OS.

Other images may be purely for aesthetics (think avatar images) and the user will have no interest in having these available in their photo library. So these should be in a hidden location and should be deleted when the app is deleted.

To achieve this, the images are usually persisted into separate storage locations, but imgcache.js appears to be fixed to a single common root location, which conflicts with this goal.

chrisben commented 6 years ago

You're correct, this library focuses on a single cache directory.

I don't see a simple way around this with the existing code. I guess the main "ImgCache" variable would have to be changed to a class, and you would have separate instances, each with their own parameters.

That could be a breaking change, unless a facade variable "ImgCache" is added for backward compatibility.

If anyone has time to do a pull request for that, I'll be glad to review it, but I won't be able to tell you when I'll be able to work on that myself.