Skip to content

Conversation

ajpallares
Copy link
Member

@ajpallares ajpallares commented Jun 20, 2025

Similar idea to RevenueCat/purchases-android#2438

Checklist

  • If applicable, unit tests
  • If applicable, create follow-up issues for purchases-android and hybrids

Motivation

Now that we allow for the developer to override the preferred locale, we need to make sure that the caching of Get Offerings considers the locales as well.

Description

Up until now, the offerings cache would only implement time-based staleness. With this PR, the offerings cache will also be considered stale if the preferred locales change.

ajpallares and others added 30 commits June 13, 2025 13:00
This reverts commit e2fd554.
Co-authored-by: JayShortway <29483617+JayShortway@users.noreply.github.com>
@ajpallares ajpallares changed the title Make Offerings cache stale when preferred locales change Consider Offerings cache stale when preferred locales change Jun 20, 2025
@ajpallares
Copy link
Member Author

I considered actively refreshing the offerings cache when receiving a different preferred language override here

@_spi(Internal) public func overridePreferredLocale(_ locale: String?) {
self.systemInfo.overridePreferredLocale(locale)
}

but I thought it would overcomplicate things and I don't really think we want to call get offerings whenever the preferred locale is overriden. WDYT @RevenueCat/coresdk?

@tonidero
Copy link
Contributor

don't really think we want to call get offerings whenever the preferred locale is overriden

I guess it depends... I would think that's an uncommon enough operation that it would be fine either way. I guess I kinda like the current lazy approach in case a customer changes the languages multiple times, so we only fetch once, when required. So yeah, I think it's fine as is!

Copy link
Member

@JayShortway JayShortway left a comment

Choose a reason for hiding this comment

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

I think this is a good improvement either way (include locale in "staleness" check), whether we proactively fetch offerings or not.

We should consider Paywalls though. We want the Paywall to be properly localized and to appear immediately, so it might be good to proactively fetch offerings. I'd say that can be a separate PR. Happy to hear thoughts! @RevenueCat/coresdk

@ajpallares
Copy link
Member Author

We should consider Paywalls though. We want the Paywall to be properly localized and to appear immediately, so it might be good to proactively fetch offerings

@JayShortway this was my thinking. But then I thought of @tonidero's argument for not doing it

I guess I kinda like the current lazy approach in case a customer changes the languages multiple times, so we only fetch once, when required.

and I don't think we should because it could be abused as a workaround to force refreshing the offerings cache.

@JayShortway
Copy link
Member

@ajpallares Hmm, good point. We could use the same rate limiter we have on syncAttributesAndOfferingsIfNeeded?

@ajpallares
Copy link
Member Author

@ajpallares Hmm, good point. We could use the same rate limiter we have on syncAttributesAndOfferingsIfNeeded?

I didn't know about that rate limiter! It seems like that would certainly solve the potential abuse of the locale API 🤔
Ok then. We can discuss this topic and decide whether we want to do the proactive get offerings on locale change then. Thanks @JayShortway!

ajpallares and others added 12 commits June 23, 2025 15:03
# Conflicts:
#	RevenueCat.xcodeproj/project.pbxproj
#	Sources/Misc/Locale/PreferredLocalesProvider.swift
#	Sources/Misc/SystemInfo.swift
#	Sources/Purchasing/Purchases/Purchases.swift
#	Tests/UnitTests/Networking/Backend/__Snapshots__/BackendGetCustomerCenterConfigTests/macOS-testGetCustomerCenterConfigPassesLocalesWithOverride.1.json
#	Tests/UnitTests/Networking/Backend/__Snapshots__/BackendGetCustomerCenterConfigTests/watchOS-testGetCustomerCenterConfigPassesLocalesWithOverride.1.json
Base automatically changed from preferred-ui-locale-in-RCUI to main July 2, 2025 18:41
@ajpallares ajpallares merged commit 280f342 into main Jul 2, 2025
12 checks passed
@ajpallares ajpallares deleted the make-cache-stale-when-preferred-locales-change branch July 2, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants