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

Add support for inherit key on cacheControl. #1424

Closed
wants to merge 2 commits into from

Conversation

lunks
Copy link

@lunks lunks commented Jul 26, 2018

This adds support for skipping using defaultMaxAge on types if inherited is
set to true. This allows to more easily cache a whole node if you do not
want or cannot set an specific maxAge.

TODO:

  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@ghost ghost added the ⛲️ feature New addition or enhancement to existing solutions label Jul 26, 2018
@apollo-cla
Copy link

@lunks: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

This adds support for skipping using defaultMaxAge on types if
inherited is set to true. This allows to more easily cache a whole
node if you do not want or cannot to set an specific maxAge.
@lunks lunks force-pushed the feature/add-inherit-support branch from 60be79b to 288693a Compare July 26, 2018 06:24
@ghost ghost added the ⛲️ feature New addition or enhancement to existing solutions label Jul 26, 2018
@evans
Copy link
Contributor

evans commented Jul 26, 2018

@lunks Thank you for the PR! Can you elaborate on the situations when you're not able to set a specific maxAge? There is a way to set it dynamically using the cacheControl object on the info object. I think documenting it's usage in the README would help clarify when inherit would be necessary.

@martijnwalraven definitely has some thoughts on this. We'd love to hear them.

#1295 is also relevant

@@ -1,5 +1,10 @@
# Changelog

### Unreleased

* Add support for `inherited` key to skip setting a `maxAge` to 0 if a
Copy link
Contributor

Choose a reason for hiding this comment

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

@lunks I wonder if it would provide more utility for inherit to be recursive, such that subfields will also inherit their cacheability as well from grandparents, etc. Basically, should inherit itself be inherited?

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly what you're proposing, I don't think that's a good idea, because it would mark an entire tree as cacheable. And I think objects should always have to opt-in to caching (even if that's through inherit).

Copy link
Contributor

Choose a reason for hiding this comment

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

For a bit of background on why I think inheritance should be opt-in, see here:
https://github.com/apollographql/apollo-cache-control-js/issues/14#issuecomment-37315847.6

@lunks
Copy link
Author

lunks commented Jul 27, 2018

@lunks Thank you for the PR! Can you elaborate on the situations when you're not able to set a specific maxAge? There is a way to set it dynamically using the cacheControl object on the info object. I think documenting it's usage in the README would help clarify when inherit would be necessary.

Sure, but first, thanks for the great project! So, my issue is: I currently have is a very slow list of images I'd like to cache. Unfortunately on other parts of the system, I need other images to not be cached because they might change a lot. So I'm left with either having a short maxAge for a type Image and thus defeating the purpose of caching, or caching for a long maxAge but having issues with Images that shouldn't cache for that long. Skipping setting maxAge of 0 for images makes the engine cache the whole query like I want for a long time, while not messing with the Image type maxAge.

I'm not sure how cacheControl in info would help, but let me know if I'm missing something.

Lastly, I'll write the docs after we have agreed on the implementation if that's ok.

@lunks I wonder if it would provide more utility for inherit to be recursive, such that subfields will also inherit their cacheability as well from grandparents, etc. Basically, should inherit itself be inherited?

It sure would. Ideally, I could do something like @cacheControl(maxAge: 30, wholeQuery: true) or something similar which would just let me set it once, but I decided to take a shot with what you initially suggested. I'm open to any as they all would solve my problem. Even a config skipping defaultMaxAge being set would work for me.

@martijnwalraven
Copy link
Contributor

So, my issue is: I currently have is a very slow list of images I'd like to cache. Unfortunately on other parts of the system, I need other images to not be cached because they might change a lot. So I'm left with either having a short maxAge for a type Image and thus defeating the purpose of caching, or caching for a long maxAge but having issues with Images that shouldn't cache for that long. Skipping setting maxAge of 0 for images makes the engine cache the whole query like I want for a long time, while not messing with the Image type maxAge.

You may already know this, but @cacheControl on fields overrides hints set on types. So setting slowListOfImages: [Image] @cacheControl(maxAge: 3600) would apply that max age to the list but wouldn't affect the max age set on the image type or on images elsewhere.

@martijnwalraven
Copy link
Contributor

In my mind, the primary use case for something like inherit is for types that should not be independently cached, like pagination nodes or edges. It's currently a pain to be forced to specify an explicit max age there, so I think it would be great to include a way to avoid that.

@martijnwalraven
Copy link
Contributor

One thing I wonder about is whether we want all cache hints to be inherited through inherit: true or make it an explicit decision to inherit specific hints through something like maxAge: "inherit".

For the former, I'm not sure what the semantics should be of combining inherit with other hints, like in @cacheControl(inherit: true, maxAge: 30). Would that only inherit the scope and override max age?

The problem with maxAge: "inherit" is that you may also want to specify scope: "inherit" to make that explicit, while in most cases you'd want to inherit all hints.

@abernix abernix added this to In progress in Data sources and caching via automation Nov 14, 2018
@hwillson hwillson moved this from In progress to To do in Data sources and caching Nov 14, 2018
@abernix abernix added the 🧬 cache-control Relates to cache directives, headers or packages. label Oct 11, 2019
@abernix
Copy link
Member

abernix commented Oct 11, 2019

I think we can re-open and re-use this code in the future if this takes root, but at this point, I believe it's mostly stalled at this point. I've tagged this for cache-control so we can reference it in future considerations.

@abernix abernix closed this Oct 11, 2019
Data sources and caching automation moved this from To do to Done Oct 11, 2019
@lunks
Copy link
Author

lunks commented Oct 11, 2019

I haven't used Apollo in a while. I'll keep the branch in case anyone wants to take over.

@chirag04
Copy link

chirag04 commented Apr 20, 2020

@abernix I share the pain point as described by lunks above: #1424 (comment). Some sort of inheritance mechanism would def. be ideal.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧬 cache-control Relates to cache directives, headers or packages. ⛲️ feature New addition or enhancement to existing solutions
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

8 participants