File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
packages/sdk/src/core/flags Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -294,16 +294,18 @@ export class CoreFlagsManager implements FlagsManager {
294294 const apiUrl = this . config . apiUrl ?? "https://api.databuddy.cc" ;
295295 const params = buildQueryParams ( this . config , user ) ;
296296
297+ const ttl = this . config . cacheTtl ?? 60_000 ;
298+ const staleTime = this . config . staleTime ?? ttl / 2 ;
299+
297300 try {
298301 const flags = await fetchAllFlagsApi ( apiUrl , params ) ;
302+ const flagCacheEntries = Object . entries ( flags ) . map ( ( [ key , result ] ) => ( {
303+ cacheKey : getCacheKey ( key , user ?? this . config . user ) ,
304+ cacheEntry : createCacheEntry ( result , ttl , staleTime ) ,
305+ } ) ) ;
299306
300- // Update cache with all flags
301- const ttl = this . config . cacheTtl ?? 60_000 ;
302- const staleTime = this . config . staleTime ?? ttl / 2 ;
303-
304- for ( const [ key , result ] of Object . entries ( flags ) ) {
305- const cacheKey = getCacheKey ( key , user ?? this . config . user ) ;
306- this . cache . set ( cacheKey , createCacheEntry ( result , ttl , staleTime ) ) ;
307+ for ( const { cacheKey, cacheEntry } of flagCacheEntries ) {
308+ this . cache . set ( cacheKey , cacheEntry ) ;
307309 }
308310
309311 this . ready = true ;
You can’t perform that action at this time.
0 commit comments