Backend#getCustomerInfo: improve logic for caching responses#486
Merged
Conversation
|
This pull request has been linked to Shortcut Story #12802: API Cache too aggressive. |
Member
|
Looks like it successfully failed 😄 |
Contributor
Author
0df49e0 to
312b635
Compare
Backend#getOfferings: improve logic for caching responses
Contributor
Author
|
@vegaro I implemented the same fix as in RevenueCat/purchases-ios#1292, and updated the PR with the details. Let me know what you think. |
vegaro
reviewed
Feb 19, 2022
Backend#getOfferings: improve logic for caching responsesBackend#getCustomerInfo: improve logic for caching responses
312b635 to
be0bcd1
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Android equivalent to RevenueCat/purchases-ios#1249 and RevenueCat/purchases-ios#1292.
Finishes [sc-12802].
Background
Before this change, the sequence illustrated by the new test
"gets updated customer after posting receipt data"would fail:When the first GET request finishes, the second one shares the cache key, so it receives the (soon to be) outdated
CustomerInfo.The fix
Unfortunately this fix is isolated for this specific issue, and not a generalized one.
I came up with several other alternatives, but what I ended up going with here involves the least amount of moving pieces.
If a
getCustomerInforequest is enqueued withpostReceiptDatain the queue, then a new unique cache key is created to avoid pastgetCustomerInfoto share outdated data.If we simply added a random number to the
getCustomerInfocache key, the test"given multiple get calls for same subscriber, only one is triggered"fails, so that's still verifying the previous behavior works.