-
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
Per-API Key Caches #74
Conversation
src/index.spec.ts
Outdated
@@ -550,7 +550,6 @@ describe('initialization options', () => { | |||
let client = await init({ | |||
apiKey, | |||
baseUrl, | |||
assignmentLogger: mockLogger, |
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.
Didn't need this 🪓
@@ -2,8 +2,14 @@ import { AssignmentCache } from '@eppo/js-client-sdk-common'; | |||
|
|||
import { hasWindowLocalStorage } from './configuration-factory'; | |||
|
|||
// noinspection JSUnusedGlobalSymbols (methods are used by common repository) |
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.
stop Webstorm for yelling at me for unused methods
src/local-storage.spec.ts
Outdated
beforeEach(() => { | ||
window.localStorage.clear(); | ||
}); | ||
|
||
describe('get and set', () => { |
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.
opted to remove the nested describe()
@@ -179,9 +179,15 @@ export async function init(config: IClientConfig): Promise<IEppoClient> { | |||
EppoJSClient.instance.stopPolling(); | |||
// Set up assignment logger and cache | |||
EppoJSClient.instance.setLogger(config.assignmentLogger); | |||
|
|||
// Note that we use the first 8 characters of the API key to create per-API key persistent storages | |||
const storageKeySuffix = config.apiKey.replace(/\W/g, '').substring(0, 8); |
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.
👍
EppoJSClient.instance.useCustomAssignmentCache( | ||
new LocalStorageAssignmentCache(storageKeySuffix), | ||
); |
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.
FYI - a factory is needed here as well https://linear.app/eppo/issue/FF-2113/create-chromestorage-assignment-cache
@@ -49,4 +49,69 @@ describe('LocalStorageAssignmentCache', () => { | |||
}), | |||
).toEqual(false); // this key has not been logged | |||
}); | |||
|
|||
it('can have independent caches', () => { |
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.
👨🍳
LOCAL_STORAGE_KEY = 'EPPO_LOCAL_STORAGE_ASSIGNMENT_CACHE'; | ||
private readonly localStorageKey: string; | ||
|
||
public constructor(storageKeySuffix?: string) { |
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.
did you consider making this a required parameter?
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 it. I suppose I should since we never really use it without one.
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.
Making this required caught a place I forgot to pass it through! Excellent suggestion!
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 love the tests. Approved, with the caveat that I'm also looking at this repo for the first time.
17d61b8
to
011f8c6
Compare
Eppo Internal:
🎟️ Ticket: FF-2230 - JS SDK - local and chrome storage caches should be isolated per-API key
During development, different environments (and thus API keys) may be used on the same device. By isolating our provided persistent storages (Local Storage, Chrome Storage, and Assignment Cache) at the per-API key level, we will prevent an SDK initialized for one environment from loading a cached configuration from a different environment.