diff --git a/package.json b/package.json index edcfe06..7731394 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/index.ts b/src/index.ts index eb39da5..b048fdd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; + /*** * 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; } export { IAssignmentEvent, IAssignmentLogger } from '@eppo/js-client-sdk-common'; @@ -94,13 +102,20 @@ export async function init(config: IClientConfig): Promise { 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; }