Requests should be cached on a per-datasource level #491
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a rather annoying bug/issue currently with how we dedup/cache queries. The current Cache takes into consideration only the
Request
, but not theDataSource
. This means that if aRequest
is reused across differentDataSource
s.For most usecases this shouldn't be a problem, because having multiple
DataSource
s returning the same type is unlikely. However, this is something that has happened to me before and failed to realise until it hit prod:In this case, if we execute a query against both datasources where the
id
exists in both of them, we would be retrieving the result from the cache even if the request was meant for a different datasource.While the workaround is simple (create another case class for the 2nd case class), I personally believe that the existing behaviour is not correct. If I'm executing a request against a specific DataSource, I expect it to be cached on the datasource that I am making a request against.
Unfortunately, the only way to fix this is by breaking the Cache API by adding DataSource as a parameter to its methods. @paulpdaniels AFAICT you were the one that asked for the Cache to be made abstract, do you see any issues with this? (assuming you ended up using a custom Cache, otherwise ignore me 😅)