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

Add an optional param to provide assignmentCache solution; fallback t… #61

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/node-server-sdk",
"version": "3.0.2",
"version": "3.0.3",
"description": "Eppo node server SDK",
"main": "dist/index.js",
"files": [
Expand Down
29 changes: 22 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>;
Copy link
Contributor

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


/***
* Timeout in milliseconds for the HTTPS request for the experiment configuration. (Default: 5000)
*/
Expand Down Expand Up @@ -61,6 +67,8 @@ export interface IClientConfig {
* Poll for new configurations even if the initial configuration request failed. (default: false)
*/
pollAfterFailedInitialization?: boolean;

disablePolling?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Consider passing a persistentStore instead which implements isExpired the way you want it:

Copy link
Contributor

Choose a reason for hiding this comment

The 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 pollAfterSuccessfulInitialization to prevent polling.

}

export { IAssignmentEvent, IAssignmentLogger } from '@eppo/js-client-sdk-common';
Expand Down Expand Up @@ -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;
}
Expand Down
Loading