File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
libs/providers/go-feature-flag/src/lib Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 1- import { GoFeatureFlagProviderOptions } from '../model' ;
1+ import { GoFeatureFlagProviderOptions , Cache } from '../model' ;
22import { EvaluationContext , Logger , ResolutionDetails } from '@openfeature/server-sdk' ;
33import { LRUCache } from 'lru-cache' ;
44import hash from 'object-hash' ;
@@ -10,7 +10,7 @@ export class CacheController {
1010 // logger is the Open Feature logger to use
1111 private logger ?: Logger ;
1212 // cache contains the local cache used in the provider to avoid calling the relay-proxy for every evaluation
13- private readonly cache ?: LRUCache < string , ResolutionDetails < any > > ;
13+ private readonly cache ?: Cache ;
1414 // options for this provider
1515 private readonly options : GoFeatureFlagProviderOptions ;
1616
@@ -20,7 +20,7 @@ export class CacheController {
2020 this . logger = logger ;
2121 const cacheSize =
2222 options . flagCacheSize !== undefined && options . flagCacheSize !== 0 ? options . flagCacheSize : 10000 ;
23- this . cache = new LRUCache ( { maxSize : cacheSize , sizeCalculation : ( ) => 1 } ) ;
23+ this . cache = options . cache || new LRUCache ( { maxSize : cacheSize , sizeCalculation : ( ) => 1 } ) ;
2424 }
2525
2626 get ( flagKey : string , evaluationContext : EvaluationContext ) : ResolutionDetails < any > | undefined {
Original file line number Diff line number Diff line change 1- import { ErrorCode , EvaluationContextValue } from '@openfeature/server-sdk' ;
1+ import { ErrorCode , EvaluationContextValue , ResolutionDetails } from '@openfeature/server-sdk' ;
22
33export interface GOFFEvaluationContext {
44 key : string ;
@@ -33,6 +33,15 @@ export interface GoFeatureFlagProxyResponse<T> {
3333 cacheable : boolean ;
3434}
3535
36+ /**
37+ * Cache is the interface used to implement an alternative cache for the provider.
38+ */
39+ export interface Cache {
40+ get : ( key : string ) => ResolutionDetails < any > | undefined ;
41+ set : ( key : string , value : ResolutionDetails < any > , options ?: Record < string , any > ) => void ;
42+ clear : ( ) => void ;
43+ }
44+
3645/**
3746 * GoFeatureFlagProviderOptions is the object containing all the provider options
3847 * when initializing the open-feature provider.
@@ -47,6 +56,9 @@ export interface GoFeatureFlagProviderOptions {
4756 // Default: null
4857 apiKey ?: string ;
4958
59+ // cache (optional) set an alternative cache library.
60+ cache ?: Cache ;
61+
5062 // disableCache (optional) set to true if you would like that every flag evaluation goes to the GO Feature Flag directly.
5163 disableCache ?: boolean ;
5264
You can’t perform that action at this time.
0 commit comments