-
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
Add an optional param to provide assignmentCache solution; fallback t… #61
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,13 @@ import { | |
FlagConfigurationRequestParameters, | ||
MemoryOnlyConfigurationStore, | ||
Flag, | ||
AssignmentCache, | ||
} from '@eppo/js-client-sdk-common'; | ||
import { Cacheable } from '@eppo/js-client-sdk-common/dist/assignment-cache'; | ||
import { ObfuscatedFlag } from '@eppo/js-client-sdk-common/dist/interfaces'; | ||
|
||
import { sdkName, sdkVersion } from './sdk-data'; | ||
|
||
|
||
/** | ||
* Configuration used for initializing the Eppo client | ||
* @public | ||
|
@@ -33,6 +34,11 @@ export interface IClientConfig { | |
*/ | ||
assignmentLogger: IAssignmentLogger; | ||
|
||
/** | ||
* (optional) Provide your own caching solution. If not defined, LRU cache will be used. | ||
*/ | ||
assignmentCache?: AssignmentCache<Cacheable>; | ||
|
||
/*** | ||
* Timeout in milliseconds for the HTTPS request for the experiment configuration. (Default: 5000) | ||
*/ | ||
|
@@ -61,6 +67,8 @@ export interface IClientConfig { | |
* Poll for new configurations even if the initial configuration request failed. (default: false) | ||
*/ | ||
pollAfterFailedInitialization?: boolean; | ||
|
||
disablePolling?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider passing a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I think we want to do what Leo said and then expose |
||
} | ||
|
||
export { IAssignmentEvent, IAssignmentLogger } from '@eppo/js-client-sdk-common'; | ||
|
@@ -94,13 +102,20 @@ export async function init(config: IClientConfig): Promise<IEppoClient> { | |
clientInstance = new EppoClient(configurationStore, requestConfiguration); | ||
clientInstance.setLogger(config.assignmentLogger); | ||
|
||
// default to LRU cache with 50_000 entries. | ||
// we estimate this will use no more than 10 MB of memory | ||
// and should be appropriate for most server-side use cases. | ||
clientInstance.useLRUInMemoryAssignmentCache(50_000); | ||
if (config.assignmentCache) { | ||
clientInstance.useCustomAssignmentCache(config.assignmentCache); | ||
} else { | ||
// default to LRU cache with 50_000 entries. | ||
// we estimate this will use no more than 10 MB of memory | ||
// and should be appropriate for most server-side use cases. | ||
|
||
clientInstance.useLRUInMemoryAssignmentCache(50_000); | ||
} | ||
|
||
// Fetch configurations (which will also start regular polling per requestConfiguration) | ||
await clientInstance.fetchFlagConfigurations(); | ||
if (!config.disablePolling) { | ||
// Fetch configurations (which will also start regular polling per requestConfiguration) | ||
await clientInstance.fetchFlagConfigurations(); | ||
} | ||
|
||
return clientInstance; | ||
} | ||
|
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 like being able to pass in the assignment cache 👍
The Vercel implementation will use their edge file