Skip to content
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

Add cache generalization & Snapshots for synchronous support #37

Merged
merged 2 commits into from
Aug 28, 2023

Conversation

z4kn4fein
Copy link
Member

@z4kn4fein z4kn4fein commented Aug 22, 2023

Describe the purpose of your pull request

This PR contains the following:

  • Enables the generalized caching feature.

  • Removes deprecated functions:

    • getVariationId() and getAllVariationIds(), alternative: getValueDetails() / getAllValueDetails().
    • refresh(), alternative: forceRefresh().
    • Init function of PollingModes.autoPoll() that had an onConfigChanged callback parameter. Alternative for subscribing to config changes: Hooks.
    • Each ***Sync() method that used DispatchSemaphore for synchronizing mainly asynchronous operations. For an alternative, see the next bullet point.
  • Introduces the concept of Snapshots. They are for capturing the actual state of the feature flag data used by the SDK. A snapshot allows synchronous operations on the captured context.

    let snapshot = configCatClient.snapshot()
    let isMyFeatureEnabled = snapshot.getValue(for: "isMyFeatureEnabled", defaultValue: false)

    Snapshots are created from the actual state of the SDK; therefore it's crucial to know whether the SDK has valid feature flag data to work on. To determine whether it's safe to create snapshots, the SDK already provides an onClientReady hook. It's being changed to accept a state parameter to give details about the SDK's initialization state.

    client.hooks.addOnReady { state in
      // the state parameter indicates what is the SDK's initialization state
    }

    These are the possible state values:

    • noFlagData: This means the SDK has no feature flag data to work on (it didn't get anything from the cache or from the network)
    • hasLocalOverrideFlagDataOnly: The SDK was initialized with localOnly flag overrides.
    • hasCachedFlagDataOnly: The SDK has feature flag data from only the cache. It can happen when the SDK is configured with PollingModes.manualPoll() and there wasn't a client.forceRefresh() call yet. Another example could be an SDK configured with PollingModes.autoPoll(), but it can't reach the ConfigCat CDN so it falls back to the cache.
    • hasUpToDateFlagData: The SDK is initialized with up-to-date feature flag data.

    This functionality was extended with a new awaitable method waitForReady() that asynchronously waits for the onClientReady hook to fire and also returns with the SDK's initialization state.

    let state = await client.waitForReady()

Related issues (only if applicable)

n/a

Requirement checklist (only if applicable)

  • I have covered the applied changes with automated tests.
  • I have executed the full automated test set against my changes.
  • I have validated my changes against all supported platform versions.
  • I have read and accepted the contribution agreement.

@z4kn4fein z4kn4fein requested a review from a team as a code owner August 22, 2023 18:51
@sonarcloud
Copy link

sonarcloud bot commented Aug 22, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@z4kn4fein z4kn4fein merged commit 23b9779 into master Aug 28, 2023
8 checks passed
@z4kn4fein z4kn4fein deleted the cache-generalization-snapshots branch August 28, 2023 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants