-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework the caching logic for subscription and entitlements #741
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some thoughts on the implementation. Not necessary blocker for merging, but they're worth pointing out IMO.
entitlementsCache: UserDefaultsCache<[Entitlement]>(subscriptionAppGroup: subscriptionAppGroup, key: UserDefaultsCacheKey.subscriptionEntitlements)) | ||
entitlementsCache: UserDefaultsCache<[Entitlement]>(subscriptionAppGroup: subscriptionAppGroup, | ||
key: UserDefaultsCacheKey.subscriptionEntitlements, | ||
settings: UserDefaultsCacheSettings(defaultExpirationInterval: .minutes(20)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a configurable param as well.
if !subscription.isActive { | ||
signOut() | ||
} | ||
} | ||
|
||
_ = await fetchEntitlements(cachePolicy: .reloadIgnoringLocalCacheData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If fetchRemoteEntitlements
returns a failure I think we should handle this. Otherwise just blocking the endpoint at router-level would make the refresh meaningless.
@@ -55,7 +56,9 @@ public final class SubscriptionService: APIService { | |||
|
|||
switch result { | |||
case .success(let subscriptionResponse): | |||
subscriptionCache.set(subscriptionResponse) | |||
let defaultExpiryDate = Date().addingTimeInterval(subscriptionCache.settings.defaultExpirationInterval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relies on system time which can be manipulated. If device time is set to a distance future, any entitlement check that depends on the cache would just succeed. While we do use reloadIgnoringLocalCacheData
when refreshing periodically, we don't currently handle the failure.
Required:
Task/Issue URL:
iOS PR: duckduckgo/macos-browser#2485
macOS PR: duckduckgo/iOS#2627
What kind of version bump will this require?: Patch
Description:
Change default staleness time interval for subscription and entitlement cache to 20min
When storing subscription in the cache use the date based on default interval or its date of renewalOrExpiry - whatever is earlier
Make the VPN code use cache and its logic for doing fetch if data is stale
On applicationDidBecomeActive refresh subscription details and entitlements
In the app rely on subscription details and entitlements based on cache logic (cached if still valid else fetch)
Internal references:
Software Engineering Expectations
Technical Design Template