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

ExpireDateCacheResolver issue #4831

Closed
ynkm169 opened this issue Apr 3, 2023 · 8 comments
Closed

ExpireDateCacheResolver issue #4831

ynkm169 opened this issue Apr 3, 2023 · 8 comments

Comments

@ynkm169
Copy link

ynkm169 commented Apr 3, 2023

Version

3.8.0

Summary

Hello.
I couldn't get it to work. This is the cache control header server send to client.
cache-control: max-age=10

Note, the following is just guesses. I am not 100% if my guess is correct. Apollo code is quite deep.
The reason it is not working is MAYBE because maybeWriteToCache seems to write empty header into cache.

  1. response.executionContext.headers size is 18 with correct header. See screenshot.

Screenshot 2023-04-03 at 5 09 24 PM

  1. response.cacheHeaders on line 75 in previous screenshot returns empty due to
  • response.cacheHeaders is implemented like this
val <D : Operation.Data> ApolloResponse<D>.cacheHeaders
  get() = executionContext[CacheHeadersContext]?.value ?: CacheHeaders.NONE
  • executionContext is an instance of HttpInfo. If you look at definition of HttpInfo, I think calling executionContext[CacheHeadersContext] on an instance of HttpInfo will always return empty.
    It should probably call this instead
    executionContext[HttpInfo]?.headers

Screenshot 2023-04-03 at 5 10 13 PM

Another thing I noticed is
StoreExpirationInterceptor intercept is returning correct expires value. However, store.writeOperation inside maybeWriteToCache is invoked before StoreExpirationInterceptor intercept.
Screenshot 2023-04-03 at 6 04 38 PM

Steps to reproduce the behavior

No response

Logs

(Your logs here)
@BoD
Copy link
Contributor

BoD commented Apr 4, 2023

Hi!

Just to be sure, are you using the incubating normalized cache (apollo-normalized-cache-incubating, apollo-normalized-cache-sqlite-incubating dependencies)?

At the moment, the storage of the cache headers (where the dates are stored) only works with those. If yes, make also sure to initialize the SQLite cache with withDates = true.

You can have a look at this test to check if anything is different in your setup.

@BoD BoD added 🗄️ Normalized cache ⌛ Waiting for info More information is required labels Apr 4, 2023
@ynkm169
Copy link
Author

ynkm169 commented Apr 5, 2023

Hello @BoD ,
apollo-rx2-support is including api(project(":apollo-normalized-cache")) as dependency. It results in duplicate dependencies build error when I add incubating version of normalized cache.

What's best way to resolve this?

@BoD
Copy link
Contributor

BoD commented Apr 5, 2023

Can you try to exclude the transitive dependency like so:

    implementation("com.apollographql.apollo3:apollo-rx2-support") {
        exclude("com.apollographql.apollo3:apollo-normalized-cache")
    }

@ynkm169
Copy link
Author

ynkm169 commented Apr 5, 2023

@BoD Thanks! I am able to compile the code now.
What could possibly be the reason lastUpdated is always null? I am trying a different expire mechanism: ReceiveDateApolloResolver.

Screenshot 2023-04-05 at 4 38 48 PM

@BoD
Copy link
Contributor

BoD commented Apr 6, 2023

@ynkm169 Did you pass withDates = true to your SqlNormalizedCacheFactory and call .storeReceiveDate(true) on your ApolloClient.Builder like in this example?

@ynkm169
Copy link
Author

ynkm169 commented Apr 6, 2023

@BoD We don't use Sql cache, only the memory cache. I understand that we can use memory cache expireAfterMilis option.
Is it possible to use server driven expiry with only memory cache?

@BoD
Copy link
Contributor

BoD commented Apr 7, 2023

Is it possible to use server driven expiry with only memory cache?

Sorry I didn't realize you were using the memory cache only! Currently this is not available with the memory cache, but only with the SQL one.

@ynkm169
Copy link
Author

ynkm169 commented Apr 7, 2023

Thanks for confirming, will close out the ticket. I don't think we currently have a use case to specify expiry at a query level. We will migrate our feature to GraphQL once this feature request is delivered: apollographql/apollo-kotlin-normalized-cache-incubating#52
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants