-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: to add cache-mode to adapter #1888
Conversation
🦋 Changeset detectedLatest commit: a27dd86 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1888 +/- ##
==========================================
+ Coverage 93.26% 93.84% +0.57%
==========================================
Files 109 109
Lines 1752 1754 +2
Branches 256 266 +10
==========================================
+ Hits 1634 1646 +12
+ Misses 118 108 -10
|
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.
Next up I'll have to plug the loading of flags from the cache into react-redux
and react-broadcast
before the initial "setState" so that there is no "flash of changing flags".
@@ -0,0 +1,36 @@ | |||
{ |
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 makes a lot of things easier. No adapter knows about a direct type (local or session storage) of cache. A facade takes care of delegating and lazily importing concrete caches.
const FLAGS_CACHE_KEY = 'flags'; | ||
const FLAGS_REFERENCE_CACHE_KEY = 'flags-reference'; | ||
|
||
function getCachePrefix(adapterIdentifiers: TAdapterIdentifiers) { |
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 allows for making it generic.
|
||
if (haveFlagsBeenWritten) { | ||
referenceCache.set( | ||
FLAGS_REFERENCE_KEY, | ||
[flagsCachePrefix, FLAGS_KEY].join('/') | ||
FLAGS_REFERENCE_CACHE_KEY, |
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.
Just renaming it.
}, | ||
}; | ||
} | ||
|
||
function getCachedFlags(cacheIdentifier: TCacheIdentifiers): TFlags { | ||
function getCachedFlags( |
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 will later be used in react-redux
and react-broadcast
.
@@ -75,38 +73,6 @@ class GraphQlAdapter implements TGraphQlAdapterInterface { | |||
readonly #getIsFlagLocked = (flagName: TFlagName) => | |||
this.#adapterState.lockedFlags.has(flagName); | |||
|
|||
readonly #getCache = async (cacheIdentifier: TCacheIdentifiers) => { |
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 for each adapter moved to the cache package.
|
||
cache.set(nextFlags); | ||
} | ||
|
||
this.#adapterState.flags = nextFlags; | ||
|
||
if (adapterArgs.cacheMode === 'lazy') { |
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.
In lazy mode we just write to the cache. No flushing of updates. The next configuration or reconfiguration (can be a reload) will flush this state "into React".
return {}; | ||
} | ||
|
||
if (adapter.effectIds) { |
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 allows us to load default flags from various adapters when combined.
Summary
Relates to #1879
This introduces the behaviour of eager and lazy cache modes. At the same time it removes the
subscribeToFlagChanges
as we always subscribe. Lastly, theunsubscribeFromCachedFlags
is almost like the lazy cache.