Clear cached offerings and products after Storefront changes (2/4)#1583
Conversation
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
…lear_cache_after_changing_Storefront
| } | ||
|
|
||
| @available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) | ||
| func testClearCachedProductsAndOfferingsAfterStorefrontChangesWithSK2() async throws { |
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
taquitos
left a comment
There was a problem hiding this comment.
This looks awesome to me, I'd love your thoughts on the .async(flags: .barrier) comment.
…to clear_cache_after_changing_Storefront
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
NachoSoto
left a comment
There was a problem hiding this comment.
I think this is ready! Looks a lot better with the logic taken out now of both fetchers :)
| } | ||
|
|
||
| func clearCache() { | ||
| self.cachedProductsByIdentifier.removeAll(keepingCapacity: false) |
|
|
||
| await productsFetcherSK2.clearCache() | ||
|
|
||
| let cachedProducts = await productsFetcherSK2.cachedProductsByIdentifier |
There was a problem hiding this comment.
I would check that this isn't empty before clearing the cache.
| self.productsFetcherSK2 = ProductsFetcherSK2() | ||
| } | ||
|
|
||
| func testCachedProductsAreEmptyAfterClearingCachedProductCorrectly() async throws { |
There was a problem hiding this comment.
I think this needs try AvailabilityChecks.iOS15APIAvailableOrSkipTest() so it gets skipped on iOS 14.
| @testable import RevenueCat | ||
|
|
||
| @available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *) | ||
| class ProductsFetcherSK2Tests: StoreKitConfigTestCase { |
There was a problem hiding this comment.
Whoa we didn't have any tests before? 😕
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
…b.com/Juanpe/purchases-ios into clear_cache_after_changing_Storefront
Yeah, totally agree. Thanks for the feedback 👍🏼 |
|
Hi guys, I made the suggested changes but I didn't re-request the review. Should I do it? Please, let me know, ok? 🙂 Thanks! |
|
I'm about to run tests on here and merge this 🎉 |
| // Note: this test passes only because the fetcher is recreated | ||
| // therefore clearing the cache. `ProductsFetcherSK2` does not | ||
| // detect Storefront changes to invalidate the cache. |
There was a problem hiding this comment.
Oh makes sense.
Can you expand this comment to explain that this is done by StoreKit2StorefrontListenerDelegate?
There was a problem hiding this comment.
Also maybe it makes more sense to call clearCache() on the fetcher to mimic the real-world behavior?
There was a problem hiding this comment.
Yep, it's a good point, let me expand it 👍🏼
There was a problem hiding this comment.
yep, I thought the same, but I wanted to use the same logic for both fetchers. 🤔 Although... I agree with you that it would mimic real-world behaviour. Let me change it
There was a problem hiding this comment.
Done ✅ (645cf5d). I've updated the test cases. Now, we clear manually the cache to mimic the real-world behaviour. Moreover, I've updated the comment to indicate that now, the changes of the Storefront are managed by the SK2 listener delegate.
I think, now it looks better 👍🏼 Thanks!
|
Thanks again for the hard work with this! |
Thank you all for the feedback and for being so patient 🙂 |
### Changes: * Replaced `CustomerInfo.nonSubscriptionTransactions` with a new non-`StoreTransaction` type (#1733) via NachoSoto (@NachoSoto) * `Purchases.configure`: added overload taking a `Configuration.Builder` (#1720) via NachoSoto (@NachoSoto) * Extract Attribution logic out of Purchases (#1693) via Joshua Liebowitz (@taquitos) * Remove create alias (#1695) via Joshua Liebowitz (@taquitos) All attribution APIs can now be accessed from `Purchases.shared.attribution`. ### Improvements: * Improved purchasing logs, added promotional offer information (#1725) via NachoSoto (@NachoSoto) * `PurchasesOrchestrator`: don't log attribute errors if there are none (#1742) via NachoSoto (@NachoSoto) * `FatalErrorUtil`: don't override `fatalError` on release builds (#1736) via NachoSoto (@NachoSoto) * `SKPaymentTransaction`: added more context to warnings about missing properties (#1731) via NachoSoto (@NachoSoto) * New SwiftUI Purchase Tester example (#1722) via Josh Holtz (@joshdholtz) * update docs for `showManageSubscriptions` (#1729) via aboedo (@aboedo) * `PurchasesOrchestrator`: unify finish transactions between SK1 and SK2 (#1704) via NachoSoto (@NachoSoto) * `SubscriberAttribute`: converted into `struct` (#1648) via NachoSoto (@NachoSoto) * `CacheFetchPolicy.notStaleCachedOrFetched`: added warning to docstring (#1708) via NachoSoto (@NachoSoto) * Clear cached offerings and products after Storefront changes (2/4) (#1583) via Juanpe Catalán (@Juanpe) * `ROT13`: optimized initialization and removed magic numbers (#1702) via NachoSoto (@NachoSoto) ### Fixes: * `logIn`/`logOut`: sync attributes before aliasing (#1716) via NachoSoto (@NachoSoto) * `Purchases.customerInfo(fetchPolicy:)`: actually use `fetchPolicy` parameter (#1721) via NachoSoto (@NachoSoto) * `PurchasesOrchestrator`: fix behavior dealing with `nil` `SKPaymentTransaction.productIdentifier` during purchase (#1680) via NachoSoto (@NachoSoto) * `PurchasesOrchestrator.handlePurchasedTransaction`: always refresh receipt data (#1703) via NachoSoto (@NachoSoto)
…#1743) Follow up to #1583. Subtask of #1382. ### Description This PR aims to invalidate and re-fetch if appropriate the stuff in the cache when the Storefront changes. I've used both `OfferingsManager` and `ProductsManager` to manage the logic of invalidate and re-fetch the data. Changes: - Add `invalidateAndReFetchCachedOfferingsIfAppropiate` method to `OfferingsManager` class. - Rename `clearCachedProducts` method to `invalidateAndReFetchCachedProductsIfAppropiate` in `ProductsManager` class. - Add `OfferingsManager` as a dependency of `PurchasesOrchestrator`. - Clear cache methods returns the identifiers of the elements that have been removed or an empty list if there was no stuff in the cache. - Add tests to cover some scenarios.

Follow up to #1557. Subtask of #1382
Description
This PR aims to clear the stuff in the cache when the Storefront changes.
Changes:
clearCachedOfferingsmethod toDeviceCache.clearCachemethod toProductFetcherSK1.internaltheclearCachemethod inProductsFetcherSK2.PurchasesOrchestator.