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' ;
2
2
import { EvaluationContext , Logger , ResolutionDetails } from '@openfeature/server-sdk' ;
3
3
import { LRUCache } from 'lru-cache' ;
4
4
import hash from 'object-hash' ;
@@ -10,7 +10,7 @@ export class CacheController {
10
10
// logger is the Open Feature logger to use
11
11
private logger ?: Logger ;
12
12
// 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 ;
14
14
// options for this provider
15
15
private readonly options : GoFeatureFlagProviderOptions ;
16
16
@@ -20,7 +20,7 @@ export class CacheController {
20
20
this . logger = logger ;
21
21
const cacheSize =
22
22
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 } ) ;
24
24
}
25
25
26
26
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' ;
2
2
3
3
export interface GOFFEvaluationContext {
4
4
key : string ;
@@ -33,6 +33,15 @@ export interface GoFeatureFlagProxyResponse<T> {
33
33
cacheable : boolean ;
34
34
}
35
35
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
+
36
45
/**
37
46
* GoFeatureFlagProviderOptions is the object containing all the provider options
38
47
* when initializing the open-feature provider.
@@ -47,6 +56,9 @@ export interface GoFeatureFlagProviderOptions {
47
56
// Default: null
48
57
apiKey ?: string ;
49
58
59
+ // cache (optional) set an alternative cache library.
60
+ cache ?: Cache ;
61
+
50
62
// disableCache (optional) set to true if you would like that every flag evaluation goes to the GO Feature Flag directly.
51
63
disableCache ?: boolean ;
52
64
You can’t perform that action at this time.
0 commit comments