firebase_image icon indicating copy to clipboard operation
firebase_image copied to clipboard

shouldCache seems to be broken

Open janlektonen opened this issue 3 years ago • 11 comments

It seems that cache is no longer working. I use latest updates from Firebase. If I state that "shouldCache: false" then I still get the old image from storage even though I have overwritten it with a new image and can also see that Created and Modified dates are updated in Storage.

If I restart my app (NOT hot-reload) then it seems to get the new image... ? But normal use of app does not use this approach.

Please check this issue as this is why I use your package... and cache seems to broken...

Thanks for great work and I love your package, Jan

janlektonen avatar Dec 14 '20 11:12 janlektonen

This is the normal behavior AFAIK. New versions are loaded only after a cold start. https://github.com/mattreid1/firebase_image/blob/7c5234e28ecd5d099bdaefad69ae76fe12ca8c47/lib/src/cache_manager.dart#L113-L116

I suspect because of the RAM cache, which is renewed only with a restart.

morphy2k avatar Dec 14 '20 17:12 morphy2k

But does shouldCache:false not make sure to force a new read of the image and not use the cache ?

janlektonen avatar Dec 14 '20 20:12 janlektonen

How can I make sure to get the latest uploadet image I just updated or created from Firestore when I read it again the first time ? Please be aware that I use the same name every time. Fx. "profileimage.jpg" But I gues you compare with metadata create/update date so I should get the latest image. But this is not what is happening. I only get the old image.. ?

janlektonen avatar Dec 14 '20 20:12 janlektonen

Firebase does not allow for us to listen to changes in a bucket in the same way we can for Realtime Database or Firestore. As such, the code will manually check the metadata for changes whenever the widget is rendered.

If you're bucket changes are somehow linked to Firestore (e.g. image upload triggers a Cloud Function then the Cloud Function updates Firestore), then you could write some code that listens for changes in Firestore and re-render the widget whenever there is an update.

Hope this clears things up!

mattreid1 avatar Dec 14 '20 21:12 mattreid1

Thanks, but I actually DO re-render the widget but still get the old image from cache and not the newest. Is there a way to force a get of the newest image and not use cache locally ? I tried "shouldCache:false" - but it gives me old cache image, not the image that is actually stored online?

janlektonen avatar Dec 14 '20 21:12 janlektonen

I'm trying to work through this as well. A cold restart is required to update the image. @janlektonen, i'd love to hear if you found a workaround. @mattreid1, the image is not seeming to evaluate on widget rendering. It only seems to be evaluating on start up. I'm referring to iOS btw.

I have tried snuffing the tempDirectory/firebase_image , all kinds of work arounds, and I can't seem to come up with a good solution to get FirebaseImage to refresh on widget rebuild when the storage image changes. It just won't do it. It seems to be that it's on a timer of sorts...but maybe this is coming from the iOS RAM as @morphy2k said? But If you can't over-ride it by completely deleting its temp directory, as I tried, what solution is there?

jbryanh avatar Jan 06 '21 19:01 jbryanh

@jbryanh, I haven't found a workaround for this. I think it could be that the newest flutter-package update from firebase might have influenced the way this package reads and handles cache from Firebase? But i'm just guessing.

I would be nice if the "shouldCache:false" just does what it is supposed to do when updating state on the widget.

@mattreid1, My solution to developer: If you reload/update state on the widget and "shouldCache" is set to false, then the image should reload from Firestore no matter what and bypass cache completely and reload image again over network from Firestore.

So I'm hoping that it will be fixed soon, please ;-)

janlektonen avatar Jan 08 '21 11:01 janlektonen

Seems to me the issues would be related. Whether shouldCache is set to false or not, on widget reload, the image should update if the image at Storage has changed, which it does not. For now, I've had to just drop the plugin so that images will refresh properly. Would sure rather use the plugin though. It's a very helpful plugin, and a huge thanks to @mattreid1 for developing it. I couldn't unwind what was keeping it from replacing the cache image myself, so I sure won't criticize.

jbryanh avatar Jan 08 '21 16:01 jbryanh

Yes, it does not work, just testet it again if it would refresh new images. But still shows old from cache, even though I force it to download with shouldCache: false.

@mattreid1 I hope you can have a look at it and see why it does not refresh when metadate change in firebase storage ?

janlektonen avatar Jan 20 '21 13:01 janlektonen

This is the normal behavior AFAIK. New versions are loaded only after a cold start. https://github.com/mattreid1/firebase_image/blob/7c5234e28ecd5d099bdaefad69ae76fe12ca8c47/lib/src/cache_manager.dart#L113-L116

I suspect because of the RAM cache, which is renewed only with a restart.

@mattreid1 Would there be a working solution around this to get it working without a restart?

janlektonen avatar Jan 20 '21 13:01 janlektonen

I think these cache plugins are GREAT if you just need static images loaded at start up that aren't dynamic or won't change in that session. I had to drop the plugin and use firebase to record the createdTimes...firebase became my repository of MetaData for images instead of Storage. That way I can compare and reload images whenever I want during widget rebuilds. Feels wonky still, but I just don't want a unique metadata read on every widget build, and I can piggyback the meta info in existing firebase docs i'm already streaming.

jbryanh avatar Jan 20 '21 14:01 jbryanh