Skip to content

Commit

Permalink
Entitlements cache fixes (#736)
Browse files Browse the repository at this point in the history
* Lower the default cache validity time to 1h

* In case of lack of entitlements clear the cache instead of storing empty array
  • Loading branch information
miasma13 authored Mar 20, 2024
1 parent 05e3446 commit 1ba3e36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Sources/Subscription/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ public class AccountManager: AccountManaging {
switch await AuthService.validateToken(accessToken: accessToken) {
case .success(let response):
let entitlements = response.account.entitlements

if entitlements != cachedEntitlements {
entitlementsCache.set(entitlements)
if entitlements.isEmpty {
entitlementsCache.reset()
} else {
entitlementsCache.set(entitlements)
}
NotificationCenter.default.post(name: .entitlementsDidChange, object: self, userInfo: [UserDefaultsCacheKey.subscriptionEntitlements: entitlements])
}
return .success(entitlements)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Subscription/UserDefaultsCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct UserDefaultsCacheSettings {
// Default expiration interval set to 24 hours
public let defaultExpirationInterval: TimeInterval

public init(defaultExpirationInterval: TimeInterval = 24 * 60 * 60) {
public init(defaultExpirationInterval: TimeInterval = 1 * 60 * 60) {
self.defaultExpirationInterval = defaultExpirationInterval
}
}
Expand Down

0 comments on commit 1ba3e36

Please sign in to comment.