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

RFC: Cache Control (also known as Time to Live, Expiration) #52

Open
martinbonnin opened this issue Jun 2, 2022 · 11 comments
Open

RFC: Cache Control (also known as Time to Live, Expiration) #52

martinbonnin opened this issue Jun 2, 2022 · 11 comments
Labels
feedback wanted Please try the feature and give us feedback 🙏💜
Milestone

Comments

@martinbonnin
Copy link
Contributor

martinbonnin commented Jun 2, 2022

In v0.0.4, a Cache Control feature has been added.

It allows to store a received or expiration date along with the fields of a record. The application can then configure max ages to types and fields, and can control what happens when resolving a field that is stale according to the stored date and field's max age.

Pleas use this ticket to give any feedback or questions regarding that feature.

@ynkm169
Copy link

ynkm169 commented Mar 22, 2023

Hi, it sounds like this ticket is to support expiry on a query level.
Would we be able to have expiry on fragment level as well?
apollographql/apollo-ios#142

@BoD
Copy link
Collaborator

BoD commented Mar 22, 2023

@ynkm169 the idea here was to control the expiry per type rather than per query or fragment. Since several queries and fragments can contribute the same fields to the cache I'm not entirely sure how this would work - but don't hesitate to tell us more about your use case and the possible API you envision.

@ynkm169
Copy link

ynkm169 commented Mar 27, 2023

@BoD Hi, per type work as well.
I am wondering what edge cases may we run into if we do it per type? In other words, does it have drawbacks that we need to make trade offs on?

  • Apollo Kotlin does not support partial cache hit. However, I imagine if done per type, you will never have partial cache hit issues since you are always querying part or all of a type.

@BoD
Copy link
Collaborator

BoD commented Mar 28, 2023

Apollo Kotlin does not support partial cache hit. However, I imagine if done per type, you will never have partial cache hit issues since you are always querying part or all of a type.

@ynkm169 situations where you will get a cache miss even though some fields are present in the cache can still happen. If a field is expired, it should behave like it is missing, and so this will result in a cache miss as well. For instance:

query getProduct {
  product(42) { 
    description { title }
    inventory { quantity }
  }
}

If description is not expired but inventory is, this should be a cache miss for product.

@ynkm169
Copy link

ynkm169 commented Apr 5, 2023

Hi, to clarify.
Will we get ability to specify expiry both

  1. on the schema type
  2. and also override the type on a particular query or fragment?

apollographql/apollo-kotlin#1 will serve as a mechanism to provide default expiry on a type
apollographql/apollo-kotlin#2 will serve as a mechanism to override expiry on a type per query/fragment

@BoD
Copy link
Collaborator

BoD commented Apr 5, 2023

I think 2. should be possible but it could be hazardous in the sense that if your field correspond to a record that is also returned by another query (cache key based on its id for instance), then this could lead to unpredictable results.

@ynkm169
Copy link

ynkm169 commented Apr 6, 2023

apollographql/apollo-kotlin#2. There are many cases regarding expiry specified in different locations that may affect the same cache entry.

  • type level expiry < query/fragment A expiry override < query/fragment B expiry override
  • query/fragment A expiry override < type level expiry < query/fragment B expiry override
  • query/fragment A expiry override < query/fragment B expiry override < type level expiry

I think this may introduce unwanted behaviors. A surface/API expect a particular cache entry to expire in 1 minute, another surface/API may modify this entry's expiry to 30seconds or 2 minutes.

Based on above, I think we wouldn't need apollographql/apollo-kotlin#2 at all.

@ynkm169
Copy link

ynkm169 commented Apr 7, 2023

Hi, is there an approximate timeline in terms of having this declarative cache expiry feature available for memory cache? Is it on the near term roadmap say within a 6 months timeline? Thanks!

@BoD
Copy link
Collaborator

BoD commented Apr 7, 2023

Our current focus is on version 4 which currently doesn't include this, and is expected to land around ~ Autumn 2023 (see the roadmap), and then we'll probably work again on this area after that.

@martinbonnin martinbonnin transferred this issue from apollographql/apollo-kotlin Oct 17, 2024
@martinbonnin
Copy link
Contributor Author

This is available in SNAPSHOTs:

repositories {
  maven {
    url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
  }
  mavenCentral()
  // other repositories...
} 

Documentation is at https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/expiration.html. Feedbacks warmly welcome.

@BoD BoD added this to the v0.0.4 milestone Nov 7, 2024
@BoD BoD added the feedback wanted Please try the feature and give us feedback 🙏💜 label Nov 7, 2024
@BoD
Copy link
Collaborator

BoD commented Nov 7, 2024

This is now available in v0.0.4.

Leaving the issue open to gather any feedback you may have 🙏

@BoD BoD changed the title 🎛️ Declarative Cache Control RFC: 🎛️ Declarative Cache Control Nov 7, 2024
@BoD BoD changed the title RFC: 🎛️ Declarative Cache Control RFC: Cache Control (also known as Time to Live, Expiration) Dec 18, 2024
@BoD BoD pinned this issue Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback wanted Please try the feature and give us feedback 🙏💜
Projects
None yet
Development

No branches or pull requests

3 participants