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

Invalidate cached image? #117

Closed
kbrmimbyl opened this issue Jan 25, 2019 · 10 comments
Closed

Invalidate cached image? #117

kbrmimbyl opened this issue Jan 25, 2019 · 10 comments

Comments

@kbrmimbyl
Copy link

kbrmimbyl commented Jan 25, 2019

Is there a way to force-invalidate a given cached image?

@wiradikusuma
Copy link

+1

@renefloor
Copy link
Collaborator

There is now.

@Xgamefactory
Copy link

There is now.
how ?

@renefloor
Copy link
Collaborator

@Xgamefactory if you import flutter_cache_manager you can call DefaultCacheManager().removeFile(String url) or DefaultCacheManager(). emptyCache()

@jagmit
Copy link

jagmit commented May 27, 2020

@renefloor Thanks for this hint! Removing the entry from the cache with DefaultCacheManager().removeFile() and causing the CachedNetworkImage to rebuild does cause a new fetching of the image over network.

Prior to 3f59818 this might could have been fixed by additionally checking whether the CacheManager still got the file in memory.

  @override
  void didUpdateWidget(CachedNetworkImage oldWidget) {
    if (oldWidget.imageUrl != widget.imageUrl || _cacheManager.getFileFromMemory(imageUrl) == null) {
      _streamBuilderKey = UniqueKey();
      if (!widget.useOldImageOnUrlChange) {
        _disposeImageHolders();
        _imageHolders.clear();
      }
      _createFileStream();
    }
    super.didUpdateWidget(oldWidget);
  }

I don't know how to do this with the new OctoImage widget. Can you look into this?

@renefloor
Copy link
Collaborator

@jagmit 'evict' should work: https://api.flutter.dev/flutter/painting/ImageProvider/evict.html
So await CachedNetworkImageProvider(url).evict() after DefaultCacheManager().removeFile().

@jagmit
Copy link

jagmit commented May 27, 2020

@renefloor Thank you for your quick reply. Evicting the image from the ImageProvider still doesn't cause the image to refetch when rebuilding the widget after the cache eviction.
Maybe the didUpdateWidget in OctoImage is the problem here?

@renefloor
Copy link
Collaborator

Have to test that, but I at least see an issue there on this line: https://github.com/Baseflow/octo_image/blob/8c33667cb5a7593651a1085edd299eb38d73be32/lib/src/image.dart#L313

@jagmit
Copy link

jagmit commented Jun 3, 2020

Were you able to reproduce it or should I try to provide an example project with this issue?

@renefloor
Copy link
Collaborator

Didn't have time for it yet, but an example is always nice to speed things up.

@expilu expilu mentioned this issue Jul 23, 2020
2 tasks
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

4 participants