-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adds LocalStorageAssignmentCache with persistent implementation between sessions to lower assignment logging; enabled by default (FF-839) #43
Conversation
…en sessions to lower assignment logging; enabled by default (FF-839)
@@ -57,8 +57,8 @@ | |||
"xhr-mock": "^2.5.1" | |||
}, | |||
"dependencies": { | |||
"@eppo/js-client-sdk-common": "^1.7.0", | |||
"axios": "^0.27.2", | |||
"@eppo/js-client-sdk-common": "2.0.0", |
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.
No more 🥕
"@eppo/js-client-sdk-common": "^1.7.0", | ||
"axios": "^0.27.2", | ||
"@eppo/js-client-sdk-common": "2.0.0", | ||
"axios": "^1.6.0", |
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.
Needed to upgrade axios
to match the major version in the commons sdk otherwise would not compile
@@ -256,6 +257,36 @@ describe('EppoJSClient E2E test', () => { | |||
}); | |||
}); | |||
|
|||
describe('LocalStorageAssignmentCache', () => { |
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.
testing the cache directly instead of as an integration with getAssignment
as those already existing in the commons
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.
🙌
|
||
public has(key: string): boolean { | ||
if (!hasWindowLocalStorage()) { | ||
return false; |
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.
Thought about throwing an error here however there's nothing with people disabling this API and functionally the SDK should continue to work.
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.
Makes sense to me too. No error throwing here 👍
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.
I think you'll want to increment the version too before merging to get this published
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.
Nice!
Outside the scope of this PR, but I wonder if we want some sort of TTL for bandits or something. Something to ponder!
@@ -256,6 +257,36 @@ describe('EppoJSClient E2E test', () => { | |||
}); | |||
}); | |||
|
|||
describe('LocalStorageAssignmentCache', () => { |
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.
🙌
try { | ||
return typeof window !== 'undefined' && !!window.localStorage; | ||
} catch { | ||
// Chrome throws an error if local storage is disabled and you try to access it |
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.
interesting!
labels: mergeable
Fixes: #issue
Motivation and Context
Downstream related change: Eppo-exp/js-sdk-common#33 enables passing an implementation.
The goal is for users of Eppo's SDK in the browser to remove duplicate assignments within and now between sessions.
We are creating a cache based on
LocalStorage
which is a unique API to browsers.Description
LocalStorage
key for the entire assignment cache - it is always for a single subject.How has this been tested?