Skip to content

fix(response_cache): do not cache data if age header is bigger than TTL#8456

Merged
bnjjj merged 4 commits intodevfrom
bnjjj/tsh_20689
Oct 20, 2025
Merged

fix(response_cache): do not cache data if age header is bigger than TTL#8456
bnjjj merged 4 commits intodevfrom
bnjjj/tsh_20689

Conversation

@bnjjj
Copy link
Contributor

@bnjjj bnjjj commented Oct 20, 2025

Given this example of headers

Cache-Control: max-age=5
Age: 90

as Age is higher than max-age it should not cache the data because it’s already expired


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • PR description explains the motivation for the change and relevant context for reviewing
  • PR description links appropriate GitHub/Jira tickets (creating when necessary)
  • Changeset is included for user-facing changes
  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Metrics and logs are added3 and documented
  • Tests added and passing4
    • Unit tests
    • Integration tests
    • Manual tests, as necessary

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices.

  4. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj requested a review from a team October 20, 2025 12:37
@apollo-librarian
Copy link
Contributor

apollo-librarian bot commented Oct 20, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* graphos/routing/(latest)/performance/caching/response-caching/observability.mdx

Build ID: 13368e9f12af6c523e1b25b3
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/13368e9f12af6c523e1b25b3

@github-actions

This comment has been minimized.

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj requested a review from a team as a code owner October 20, 2025 12:39
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this file to only keep one version between response caching and entity caching


pub(crate) fn elapsed_inner(&self, now: u64) -> u32 {
(now - self.created) as u32
pub(crate) fn elapsed_inner(&self, now: u64) -> i128 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I return i128 to accept negative values. Because if I return 0 in case created is bigger than current_epoch_time it's a bug and we should not use 0 as value for elapsed it would be incorrect.

// FIXME: should we add support for must-understand?
// public will be the default case
!self.no_store
!self.no_store && self.ttl().map(|ttl| ttl > 0).unwrap_or(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to avoid the case where age header is bigger than max-age because in ttl() if we have both max-age and age set we now do max_age.saturating_sub(*age) which means it will be 0 instead of the previous overflow.

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj merged commit 88b0438 into dev Oct 20, 2025
15 checks passed
@bnjjj bnjjj deleted the bnjjj/tsh_20689 branch October 20, 2025 14:19
@abernix abernix mentioned this pull request Oct 27, 2025
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 this pull request may close these issues.

2 participants