flutter_cache_manager icon indicating copy to clipboard operation
flutter_cache_manager copied to clipboard

New configuration respectMaxAgeZero

Open aytchell opened this issue 3 months ago • 0 comments

If a server sends "Cache-Control: max-age=0" this might be a misconfiguration on the server; in this case we should ignore it (the behaviour up to now). It might also mean, that the content potentially already expired; for this case this commit provides a new configuration parameter to react on this response and configure the validity duration of such a response.

:sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

New configuration parameter so that on Cache-Control: max-age=0 we can configure the validity duration (it even can be treated the same as Cache-Control: no-cache by setting the parameter to Duration(seconds: 0)).

:arrow_heading_down: What is the current behavior?

Currently, if the server responds with Cache-Control: max-age=0, the library ignores this and sets the max-age to one week.

:new: What is the new behavior (if this is a feature change)?

See above. The default behavior is left as-is.

:boom: Does this PR introduce a breaking change?

No

:bug: Recommendations for testing

:memo: Links to relevant issues/docs

I've seen the discussion in https://github.com/Baseflow/flutter_cache_manager/issues/283

In my app I have this issue: I'm contacting an API (which I cannot control or change) and this API delivers "some kind of" real time data (results for sport games). The server delivers json files; the response contains an etag header and the header Cache-Control: max-age=0. So I periodically poll this endpoint and if the etag is still valid I go with the cached file.

But the current behavior of the lib gives me the cached file regardless if the json changed or not. By setting the Config parameter which is introduced here, I can properly work with the API.

I added a new FAQ to the README.md.

:thinking: Checklist before submitting

  • [x] All projects build
  • [x] Follows style guide lines (code style guide)
    • I mostly followed the style guide; but (I'm new to flutter) I got an error when running flutter format . and dart format . reformatted the whole project. So ... I hope the code formatting is fine.
  • [x] Relevant documentation was updated
  • [x] Rebased onto current develop

aytchell avatar Oct 05 '25 12:10 aytchell