Clearing a JUCE::ImageCache

Is there a way to clear a JUCE::ImageCache?

I only see ImageCache::releaseUnusedImages(), but that does not have the behaviour I want. If I load an image from a path, and then clear the cache, and then load another instance of Image from the same path, I want that second instance to be reloaded from disk (because I cleared the cache in between). Is that possible somehow?

Thanks!

Related to that: is it somehow possible to have more than one JUCE::ImageCache? Currently, I can only see how to have a global singleton one. But global state is sometimes not good… this precludes using RAII for managing/clearing the image cache.

Yes, you can only clear the cache by nullifying any of your active Images that came from the cache and then immediately calling releaseUnusedImages()

It seems ImageCache is intended only to be used as a global singleton cache… would love to see it become non-global so it can be managed in the way you’re describing :slight_smile:

Thanks. Oh well, then I need to implement my own ImageCache…

It’s just ~200 lines of code so should be doable.

The cache works simply by sharing the images.
If you pull an image from ImageCache, you can overwrite the pixels and all other instances will follow.
Does that help?

I don’t think so.

When I request an image, I need to control whether it’s cached or not, independently from whether cached versions of it were retrieved previously and whether or not those are still around somewhere.