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

caching of 404 responses #965

Open
qeepcologne opened this issue Aug 19, 2024 · 2 comments
Open

caching of 404 responses #965

qeepcologne opened this issue Aug 19, 2024 · 2 comments

Comments

@qeepcologne
Copy link

qeepcologne commented Aug 19, 2024

🚀 Feature Requests

we fetching image like that which works pretty fine, with the exception of 404 response.
Then the image is requested again and again.
Don't know why they are not cached (status code or empty response?).
Headers should be correct (The images never change (when content change, the uri will change, so we set the immutable header).

CircleAvatar(
    foregroundImage: userImage(_partner!),
    backgroundImage: defaultImage(_partner!))                     

userImage(User partner) => (partner.pictureUrlDisplay != null)
    // there is no configuration, image caching depends on cache control header send by the server
    ? CachedNetworkImageProvider(
        partner.pictureUrlDisplay!,
        headers: userImageHeaders,
        errorListener: (err) {
          _logger.w("failed to load image: $err");
        },
      )
    : defaultImage(partner);

defaultImage(User partner) =>
    AssetImage((partner.gender == "man") ? "assets/image_not_found_man.webp" : "assets/image_not_found_woman.webp");

Describe the feature

allow caching of 404 image requests depending on cache headers.
Server already returns suitable header
Cache-Control: immutable, max-age=86400
If needed add config similar to CacheOptions in DioCacheInterceptor
hitCacheOnErrorExcept: [403, 503, 521], // do not cache temporary errors

@RabeaBarabea
Copy link

why the the CachedNetworkImage widget throws an error , when the given URL is invalid , even error handler exists , this causes a test failed in widget testing

@qeepcologne
Copy link
Author

maybe this is the reason:
https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/cache_manager.dart
(underlying cache manager removes it when status code is 404).

@qeepcologne qeepcologne changed the title cacheing of 404 responses caching of 404 responses Oct 10, 2024
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

2 participants