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

Feature request: easy way to pre-cache by url #26

Closed
lukepighetti opened this issue Feb 17, 2021 · 6 comments · Fixed by #33 · May be fixed by #27
Closed

Feature request: easy way to pre-cache by url #26

lukepighetti opened this issue Feb 17, 2021 · 6 comments · Fixed by #33 · May be fixed by #27

Comments

@lukepighetti
Copy link

lukepighetti commented Feb 17, 2021

We'd love to be able to fire off a command to pre-cache a Firestore image url.

ie

final url = "gs://vgl-xxxa.appspot.com/users/xxxxx/avatars/xx-xx-xx-a2fb-xx.jpg";
FirebaseImageCacheManager.precache(url);
@yelkamel
Copy link

that should be great

@lukepighetti
Copy link
Author

@mattreid1 if you can recommend a strategy to implement this I will get it done and make a PR

@mattreid1
Copy link
Owner

In one of my tests I actually run something like this if I'm not mistaken....

void setBytes() async {
  Uint8List imageBytes =
      (await FirebaseImage('gs://xxxxxxxxx.appspot.com/xxxx.jpg')
          .getBytes()); // This fetches the image 

  setState(() {
    bLength = imageBytes.length;
  });
}

Would something like this achieve what you need?

@lukepighetti
Copy link
Author

Check the PR I made, #27

@mattreid1
Copy link
Owner

Take a look at the PR I just made #33.

It's async, avoids logic duplication, very simple, null safe and throws a descriptive error if the developer has accidentally disabled caching.

You can use it by calling this anywhere in the code.

FirebaseImage('gs://xxxxxxxxx.appspot.com/xxxx.jpg').preCache();

Might be worth me disabling the max file size limit for pre-caches (or setting it high e.g. 50MB). Thoughts?

If you're happy this solves the issue, I'll publish this.

@lukepighetti
Copy link
Author

lukepighetti commented Mar 12, 2021

I'm not able to test it right this moment but if that does cache the image so it's instant retrieval the next time you make a FirebaseImage with that URL than I much prefer your solution and I'd be happy for my PR and this issue to be closed.

@mattreid1 mattreid1 linked a pull request May 1, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants