-
Notifications
You must be signed in to change notification settings - Fork 2
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 NormalizedCacheFactory.close() #67
base: main
Are you sure you want to change the base?
Conversation
expect fun SqlNormalizedCacheFactory(driver: SqlDriver): NormalizedCacheFactory | ||
fun SqlNormalizedCacheFactory(driver: SqlDriver): NormalizedCacheFactory = SqlNormalizedCacheFactory(driver, false) | ||
|
||
internal fun SqlNormalizedCacheFactory(driver: SqlDriver, manageDriver: Boolean): NormalizedCacheFactory = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The manageDriver
here seems inconsistent. I would avoid having to manually define ownership. There are 2 cases:
- We want the connection to be shared accross multiple clients => expose it as a public property so the user can retrieve and close it manually if they want to. (see OkHttpClient.dispatcher.executorService.shutdown()).
- We want ApolloClient to own the connection => close it systematically.
Option 1. is not breaking current behaviour. On the other hand, 2. is probably what most users expect by default. At the end of the day, it all boils down to whether there's a good case for sharing a connection. I would intuitively say "no" but haven't thought that completely through.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like 1! If we expose the driver, there's no need for a close
.
About 2, yeah currently it's possible to pass the same factory to multiple clients, which should probably be forbidden?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's possible to pass the same factory to multiple clients, which should probably be forbidden?
If we forbid sharing a connection between multiple clients, we might as well close the connection systematically when the client is closed. At first sight I would say this is what the majority of users expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot that ApolloClient.close has no knowledge of ApolloStore 😅 To make this happen we could add a sorry I meant ApolloStore.manage(Closeable)
ApolloClient.manage(Closeable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either that or ApolloInterceptor.close()
(HttpInterceptor
has something like this already for batching IIRC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Left one comment. Also probably needs to land in the non-incubating version.
Related to #66
SqlNormalizedCacheFactory.close()
will callclose()
on theSqlDriver
it creates - if you pass your own driver, it won't close it.