Skip to content

Auto-invalidate VC cache for verified rewards#6765

Merged
polmiro merged 5 commits into
mainfrom
rcadmob-auto-invalidate-vc-cache-on-verified-reward
May 12, 2026
Merged

Auto-invalidate VC cache for verified rewards#6765
polmiro merged 5 commits into
mainfrom
rcadmob-auto-invalidate-vc-cache-on-verified-reward

Conversation

@polmiro

@polmiro polmiro commented May 11, 2026

Copy link
Copy Markdown
Member

Checklist

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

Motivation

When reward verification returns a verified virtual-currency payload in the AdMob adapter, integrators currently need to remember to manually invalidate RevenueCat virtual currencies cache before fetching an updated balance. This is easy to miss and leads to stale balance reads.

Description

  • Automatically invalidate virtual currencies cache when reward verification yields .verified(.virtualCurrency(...)).
  • Keep behavior scoped: do not invalidate for .verified(.noReward), .verified(.unsupportedReward), or .failed.
  • Keep mapOutcome side-effect free and perform invalidation in the main-actor callback dispatch path before delivering rewardVerificationResult.
  • Add callback-path tests in PresentRewardVerificationTests to verify invalidation behavior for each outcome type.
  • Keep mapping tests in PresentMappingTests focused on pure mapping behavior.
  • Update adapter docs and sample README to clarify cache invalidation is automatic for verified virtual-currency rewards, while balance refetching remains app-driven.

Testing

  • swiftlint lint AdapterSDKs/RevenueCatAdMob/Sources/RevenueCatAdMob/RewardVerification/RewardVerification.swift AdapterSDKs/RevenueCatAdMob/Sources/RevenueCatAdMob/RewardVerification/RewardedAds+RewardVerification.swift AdapterSDKs/RevenueCatAdMob/Tests/RevenueCatAdMobTests/PresentMappingTests.swift AdapterSDKs/RevenueCatAdMob/Tests/RevenueCatAdMobTests/PresentRewardVerificationTests.swift
  • xcodebuild test -scheme "RevenueCatAdMob" -destination "platform=iOS Simulator,OS=18.4,name=iPhone 16"

Note

Medium Risk
Adds a new automatic side effect (invalidating RevenueCat virtual-currency cache) on the reward-verification success path, which can affect integrators’ balance-refresh behavior and requires Purchases configuration checks.

Overview
Automatically invalidates RevenueCat’s virtual-currency cache when reward verification completes with .verified(.virtualCurrency(...)), doing the side effect on the main-actor callback path before invoking rewardVerificationResult (and warning if Purchases isn’t configured).

Updates the reward-verification handler API to support optional result callbacks and injectible invalidation for testing, and expands unit coverage to assert invalidation happens only for verified virtual-currency outcomes.

Documentation in the adapter README and integration sample is updated to clarify that cache invalidation is adapter-managed and apps only need to refetch balances when they need fresh UI.

Reviewed by Cursor Bugbot for commit 6ac5565. Bugbot is set up for automated code reviews on this repo. Configure here.

@polmiro polmiro added the pr:fix A bug fix label May 11, 2026
@polmiro polmiro changed the title fix: auto-invalidate virtual currencies cache for verified rewards Auto-invalidate virtual currencies cache for verified rewards May 11, 2026
@polmiro polmiro requested a review from ajpallares May 11, 2026 16:10
@polmiro polmiro marked this pull request as ready for review May 11, 2026 16:10
@polmiro polmiro requested a review from a team as a code owner May 11, 2026 16:10
@polmiro polmiro changed the title Auto-invalidate virtual currencies cache for verified rewards fix: auto-invalidate VC cache for verified rewards May 11, 2026

@ajpallares ajpallares 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.

Nice touch! Great QoL improvement, for sure. I have some suggestions for the implementation though

@polmiro polmiro changed the title fix: auto-invalidate VC cache for verified rewards Auto-invalidate VC cache for verified rewards May 12, 2026
@polmiro polmiro added pr:other pr:admob and removed pr:fix A bug fix labels May 12, 2026
polmiro added 4 commits May 12, 2026 11:49
Invalidate RevenueCat virtual currencies cache automatically when reward verification returns a verified virtual currency so integrators get fresh data without manual invalidation. Update adapter docs and add tests covering when invalidation should and should not run.
Keep outcome mapping side-effect free and perform virtual currencies cache invalidation only in the main-actor reward verification callback path. Add callback-level tests to verify invalidation runs only for verified virtual currency outcomes.
Remove the extra PresentMapping test additions from this PR so the diff stays focused on virtual-currency cache invalidation behavior.
Limit virtual-currency cache invalidation testing to the reward callback boundary by injecting the invalidation closure into the handler, while keeping production behavior on the main actor. This avoids mutable global test hooks and clarifies test naming around createUserDidEarnRewardHandler semantics.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c91c537. Configure here.

@polmiro polmiro force-pushed the rcadmob-auto-invalidate-vc-cache-on-verified-reward branch from c91c537 to e55d7b8 Compare May 12, 2026 10:30
Add explicit warning logging when virtual-currency cache invalidation is skipped because Purchases is not configured, matching existing reward verification observability patterns.
@polmiro polmiro requested a review from ajpallares May 12, 2026 10:46

@ajpallares ajpallares 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.

Great job!

@polmiro polmiro merged commit 532d36c into main May 12, 2026
40 of 41 checks passed
@polmiro polmiro deleted the rcadmob-auto-invalidate-vc-cache-on-verified-reward branch May 12, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants