Skip to content

Backend#getCustomerInfo: improve logic for caching responses#486

Merged
NachoSoto merged 1 commit into
mainfrom
api-cache-ordering
Feb 22, 2022
Merged

Backend#getCustomerInfo: improve logic for caching responses#486
NachoSoto merged 1 commit into
mainfrom
api-cache-ordering

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Feb 14, 2022

Copy link
Copy Markdown
Contributor

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:

  • GET /subscribers/
  • POST /receipts
  • GET /subscribers/

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 getCustomerInfo request is enqueued with postReceiptData in the queue, then a new unique cache key is created to avoid past getCustomerInfo to share outdated data.

If we simply added a random number to the getCustomerInfo cache key, the test "given multiple get calls for same subscriber, only one is triggered" fails, so that's still verifying the previous behavior works.

@NachoSoto NachoSoto added the bug label Feb 14, 2022
@NachoSoto NachoSoto requested review from a team, taquitos and vegaro February 14, 2022 20:03
@shortcut-integration

Copy link
Copy Markdown

This pull request has been linked to Shortcut Story #12802: API Cache too aggressive.

@vegaro

vegaro commented Feb 15, 2022

Copy link
Copy Markdown
Member

Looks like it successfully failed 😄

@NachoSoto

Copy link
Copy Markdown
Contributor Author

drop mic

@NachoSoto NachoSoto changed the title Example of aggressive API cache Backend#getOfferings: improve logic for caching responses Feb 15, 2022
@NachoSoto

Copy link
Copy Markdown
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.

Comment thread common/src/main/java/com/revenuecat/purchases/common/Backend.kt Outdated
@NachoSoto NachoSoto changed the title Backend#getOfferings: improve logic for caching responses Backend#getCustomerInfo: improve logic for caching responses Feb 19, 2022
@NachoSoto NachoSoto requested a review from vegaro February 19, 2022 18:29

@vegaro vegaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!!

@NachoSoto NachoSoto merged commit c4254df into main Feb 22, 2022
@NachoSoto NachoSoto deleted the api-cache-ordering branch February 22, 2022 21:55
@beylmk beylmk mentioned this pull request Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants