Skip to main content
Solved

"Fetch or cached (and error)" policy for getCustomerInfo

  • September 27, 2024
  • 1 reply
  • 38 views

ptorab
Forum|alt.badge.img

Is there a fetch policy for getCustomerInfo that translates to,

  1. Go to network, get the most recent
  2. If network fails, use cache if not stale
  3. Return error if cache is stale

Basically, “fetchedOrNotStaleCached”, borrowing from the policy names below. Is there any reason this is not supported (so I don’t try to create it through extra code either)? I thought maybe a rate limit is behind this, but not sure now (it seems a rate limit of 5 minutes for this type of policy for example would become effectively “notStaleCachedOrFetched”).    

public enum CacheFetchPolicy: Int {

    /// Returns values from the cache, or throws an error if not available.
    case fromCacheOnly

    /// Always fetch the most up-to-date data.
    case fetchCurrent

    /// Returns the cached data if available and not stale, or fetches up-to-date data.
    /// - Warning: if the cached data is stale, and fetching up-to-date data fails (if offline, for example)
    /// an error will be returned instead of the outdated cached data.
    case notStaleCachedOrFetched

    /// Default behavior: returns the cached data if available (even if stale), or fetches up-to-date data.
    case cachedOrFetched

    /// Default ``CacheFetchPolicy`` behavior.
    public static let `default`: Self = .cachedOrFetched

}

 

Best answer by Ryan Glanz

This is how we cache customerInfo: https://www.revenuecat.com/docs/test-and-launch/debugging/caching#customerinfo

We don’t have the fetch policy you’re describing, mostly due to performance reasons (that method can be called many times throughout the app’s lifecycle, which would lead to many network calls), so you many need to build this behavior yourself.

View original
Did this post help you find an answer to your question?
This post has been closed for comments

1 reply

Ryan Glanz
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 383 replies
  • Answer
  • October 1, 2024

This is how we cache customerInfo: https://www.revenuecat.com/docs/test-and-launch/debugging/caching#customerinfo

We don’t have the fetch policy you’re describing, mostly due to performance reasons (that method can be called many times throughout the app’s lifecycle, which would lead to many network calls), so you many need to build this behavior yourself.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings