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

Adds LocalStorageAssignmentCache with persistent implementation between sessions to lower assignment logging; enabled by default (FF-839) #43

Merged
merged 4 commits into from
Dec 22, 2023

Conversation

leoromanovsky
Copy link
Member

@leoromanovsky leoromanovsky commented Dec 18, 2023


labels: mergeable

Fixes: #issue

Motivation and Context

Downstream related change: Eppo-exp/js-client-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

  • Use only a single LocalStorage key for the entire assignment cache - it is always for a single subject.
  • Instantiate the js client with this cache.

How has this been tested?

  • New integration test.

@leoromanovsky leoromanovsky marked this pull request as ready for review December 18, 2023 23:31
@@ -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",
Copy link
Member Author

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",
Copy link
Member Author

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', () => {
Copy link
Member Author

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

Copy link
Contributor

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;
Copy link
Member Author

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.

Copy link
Contributor

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 👍

Copy link
Contributor

@sameerank sameerank left a 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

Copy link
Contributor

@aarsilv aarsilv left a 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', () => {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting!

@leoromanovsky leoromanovsky merged commit e27e49a into main Dec 22, 2023
2 checks passed
@leoromanovsky leoromanovsky deleted the lr/ff-839/persistent-cache-js branch December 22, 2023 06:03
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.

3 participants